Does anyone know a good tool that would give me x86 instruction execution count. I have looked at gcov, but would like to look at other option that might help me. My Ultimate goal is to be able to call this function and give it the function I am interested in emulating/profiling and it would return the number of times each assembly line executed. Any suggestions are welcome :) Thanks
4 Answers
Qemu could help, but any way this kind of profiling will ruin your cache/pipeline profile and won't be useful.

- 9,605
- 1
- 23
- 35
-
Qemu requires modifications. I want something simple that would for example generate something like: 25 add %eax, 12(%esp) 25 j test 1 lea %ebx,16(%eax) were add and j are executed 25 times and lea is executed only once! i once came upon a scripting code that did such a thing, but accidently closed the webpage – Syntax_Error Dec 16 '10 at 18:15
-
@Syntax_Error: it's not useful at all, and hardly could be called profiling. In most cases speed will depend of cache and pipeline, and not on these stats. Is it for a school project? – ruslik Dec 16 '10 at 18:19
-
@ruslik: you are absolutely right, that is why I am not using the data for the speed. I just want to detect the most executing instruction in a function. – Syntax_Error Dec 16 '10 at 18:22
-
@Syntax_Error: then use an emulator. Profilers do something completely different. – ruslik Dec 16 '10 at 18:25
-
@ruslik: Im up to anything that can do so. are there any emulators that do it without the need of modifying the source code? – Syntax_Error Dec 16 '10 at 18:31
-
@Syntax_Error: it has nothing to do with source code either. You just have to run your binary in the emulator. – ruslik Dec 16 '10 at 18:39
-
You could slap together a program like that pretty easily on Linux, just use ptrace
in combination with objdump
and some logic, should be easy to write in asm
.
I got the idea from How to code debuggers.

- 1,048,767
- 296
- 4,058
- 3,343

- 1
If you are looking for instructions that account for a significant percent of time, and if you can run it under a debugger, then this will work. It will isolate code points that are responsible for significant time, whether they are terminal instructions or function call instructions, even if they cause I/O.
Tools that will do this are Zoom, if you are on Linux, or LTProf if on Windows.
On the other hand, if you are looking for time measurement and execution counting, you will need something else, like an emulator (Valgrind?).

- 1
- 1

- 40,059
- 14
- 91
- 135
-
Thanks Mike. However I am doing tests on benchmarks so I dont have the flexibility of modifying the source code so I can't manually do it for such kernels. My ultimate goal is to be able to call this function and give it assembly files and it will emulate or profile the specific function and give me each instruction execution count. Do you know of any? – Syntax_Error Dec 16 '10 at 18:42
-
@Syntax_Error: You shouldn't have to modify the source code, but nevertheless, since you're more interesting in timing than in speedups, an emulator like Valgrind might be able to do what you need. Good luck. – Mike Dunlavey Dec 16 '10 at 22:23
AMD's code analyst should be able to do this using instruction based sampling, I can't remember if it gives percentages or flat numbers for execution counts though.

- 25,836
- 3
- 63
- 101