Number of instructions executed

Hello,

I’m executing my byte code program by the lli tool using mcjit.

I need a way to find statistics about the number of instructions executed for my program…

The –stats option does not include this value, are there any other way to know?

I need this information to compare different versions of my bytecode program.

Please advice

Thanks in advance

Sara Elsohbaky

I forget the name now, but there's an emulator which has this capability. There's also performance counters available on some platforms that may give you access to this. PAPI or perfmon2 may have this capability. I guess this may not be exactly what you want, but hopefully it helps.

I forget the name now, but there's an emulator which has this capability.
There's also performance counters available on some platforms that may give
you access to this. PAPI or perfmon2 may have this capability. I guess this
may not be exactly what you want, but hopefully it helps.

Pin is probably the most straightforward way to obtain dynamic
instruction count on x86. Valgrind/QEMU/DynamoRIO all have that
capability, though I don't remember how easy it is to tease the
information out of each tool.

Valgrind's tool Callgrind can show number of instructions executed between two
arbitrary points in code using so-called client requests [1].

Example:

#include <valgrind/callgrind.h>

void someFunction()
{
  CALLGRIND_START_INSTRUMENTATION;
  // code fragment where you'd like to measure instruction count
  CALLGRIND_STOP_INSTRUMENTATION;
}

Then compile and run valgrind --tool=callgrind --instr-atstart=no ./yourprogram
to see number of instructions executed between start and stop points.

I have not tried this with JIT, but I guess it should work the same way:
start instrumentation between calling JIT'ed function, and stop it right
after this call.

[1] http://valgrind.org/docs/manual/cl-manual.html#cl-manual.clientrequests

You can usually do this sort of things with the profiling library (profile_rt), but I don't know if it will work with MCJIT.

A similar problem is solved here: http://fromhelloworld.wordpress.com/2011/10/12/intro-to-llvm/