I want to obtain the percentage of memory read-write instructions in a test program, preferably dynamically. Apart from counting instructions in the gdb asm dump, which is static anyway, is there an easier way to obtain it? Valgrind provides total heap usage. Perf has some nice features but does not support WSL. Pin has an instruction count capability but it I am not sure if it supports WSL.
(Update: PIN reportedly doesn't work under WSL. But it doesn't require perf counters so it's still useful in VMs or whatever.)
Have you tried PIN, or SDE which is built on top of PIN and does what you want? https://software.intel.com/en-us/articles/intel-software-development-emulator sde64 -mix -- ./my-program will tell you if PIN works, and might solve your problem all on its own. SDE's instruction mix is by mnemonic IIRC, maybe not by memory destination vs. src, but at least you'll know that PIN will work before you sink any time into writing a custom PIN tool.
sde64 -mix -- ./my-program
PIN is based on dynamic runtime instrumentation, not performance counters. It probably doesn't even cath SIGILL (not that WSL would have a prob. with that); it has to emulate lzcnt on CPUs where it decodes as rep bsr, and stuff like that.
lzcnt
rep bsr
So I doubt PIN needs much kernel support beyond the ability to JIT (which stuff like Java and web browser JS engines need, and is just mmap(PROT_EXEC)). It might use ptrace, but if GDB works under WSL then hopefully PIN will.
mmap(PROT_EXEC)
See also Tools to count number of different types of instructions in x86 assembly to create a dynamic instruction mix table.
Related: How do I determine the number of x86 machine instructions executed in a C program? isn't WSL-specific, but mentions sde64 -mix.
sde64 -mix
2.1m questions
2.1m answers
60 comments
57.0k users