Search code examples
linuxperformanceprofilingx86-64instructions

Monitoring the instructions of a running program in ubuntu?


I'm a little stuck here.

The idea is that I'd like to get a file of every instruction run by a program during it's execution. I'd like to do it with just the executable in hand (no source) and be able to determine what operation is occuring on what address when.

For example, I'd like to be able to run it on Google Chrome, Firefox, etc.

I want to use this for a performance prediction system I'm working on. I figure if I'm able to obtain each instruction that is executed in order it is executed on system 1, I can attempt to simulate/model the run time of an identical program being run on system 2, because I'll be able to predict(although I know not with 100% accuracy) L1/L2 cache-misses, L1/L2 cache-hits, TLB hits/misses, page faults, time taken on floating point multiplication operations, etc.

I'd like to try to do this on two different systems:

System 1: Ubuntu 10.10 on Intel Core 2 Duo CPU

System 2: Ubuntu 12.04 on system with 2x AMD Sixteen Core Opteron model 6274

(I can definitely change the OS's as neccessary, but would prefer to stay with Ubuntu, if possible)

Is this possible / how could I go about doing it? I know with debuggers, you can use them to step through everything, but I don't have the source available.


Solution

  • I think, you can use qemu (or even bochs) or valgrind to monitor every executed instruction. They are x86 binary translation tools (excluding bochs - which is an interpreter of x86 code). There is a valgrind tool called cachegrind (+ kcachegrind gui), which is ready to emulate cache by instrumenting every memory access and simulating some L1/L2 cache model (sizes may be configured via command line options).

    To get deeper (into pipeline) you may want to look on free ptlsim (http://www.ptlsim.org/)