问题
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.
回答1:
(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-emulatorsde64 -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.
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.
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.
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
.
回答2:
valgrind tools are doing a lot more than providing the total heap usage.
See valgrind user manual http://www.valgrind.org/docs/manual/manual.html
In particular, look at the sections describing the valgrind tools callgrind and cachegrind.
http://www.valgrind.org/docs/manual/cg-manual.html
http://www.valgrind.org/docs/manual/cl-manual.html
来源:https://stackoverflow.com/questions/58243626/how-to-characterize-a-workload-by-obtaining-the-instruction-type-breakdown