Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

assembly - How to characterize a workload by obtaining the instruction type breakdown?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

(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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...