How to profile the LLVm JITed Code

I’m using llvm 3.3,which was built with the options below:

…/llvm-3.3.src/configure --prefix=/home/admin/jianzhang.zj/llvm/llvm-install-2/ --with-gcc-toolchain=/home/admin/jianzhang.zj/gcc-4.8.2-install/ --enable-optimized --enable-debug-runtime --enable-debug-symbols --disable-assertions --with-oprofile=/home/admin/jianzhang.zj/oprofile-0.9.9-install/ --enable-profiling --with-intel-jitevents

The oprofile’s version is 0.99

I’m using the following Makefile to build the Fibonacci examples in the llvm source code:

LLVM_FLAGS=$(shell $(LLVM_CONFIG) --cxxflags --cppflags --ldflags --ldflags --libs )
COMMON_FLAGS= -DTEST -DMCJIT -g -rdynamic -O3 -lpthread -ldl
INCLUDE = -I/home/admin/jianzhang.zj/llvm/llvm-install-2/include/
PROGRAM= fibonacci
all: clean output
output: $(PROGRAM)
$(CXX) $@.cpp $(INCLUDE) -o $@ $(COMMON_FLAGS) $(LLVM_FLAGS) -fexceptions
rm -f $(PROGRAM) *.o LOG

then I use the operf command to sampling:

$ /home/admin/jianzhang.zj/oprofile-0.9.9-install/bin/operf ./fibonacci 40
operf: Profiler started
verifying… OK
We just constructed this LLVM module:

; ModuleID = ‘test’
define i32 @fib(i32 %AnArg) {
%cond = icmp sle i32 %AnArg, 2
br i1 %cond, label %return, label %recurse
return: ; preds = %EntryBlock
ret i32 1
recurse: ; preds = %EntryBlock
%arg = sub i32 %AnArg, 1
%fibx1 = tail call i32 @fib(i32 %arg)
%arg1 = sub i32 %AnArg, 2
%fibx2 = tail call i32 @fib(i32 %arg1)
%addresult = add i32 %fibx1, %fibx2
ret i32 %addresult

starting fibonacci(40) with JIT…
Result: 102334155
Profiling done.

then use opreport:

$ /home/admin/jianzhang.zj/oprofile-0.9.9-install/bin/opreport
Using /apsarapangu/disk8/jianzhang.zj/llvm/llvm-3.3.src/examples/Fibonacci/oprofile_data/samples/ for samples directory.
CPU: Intel Sandy Bridge microarchitecture, speed 2199.75 MHz (estimated)
Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000

samples> %
16252 100.000 fibonacci
samples> %

15368 94.5607 anon (tgid:60546 range:0x7faa17b40000-0x7faa17bbffff)
656 4.0364 no-vmlinux
139 0.8553
54 0.3323 fibonacci
33 0.2031
2 0.0123

here the ‘anon (tgid:60546 range:0x7faa17b40000-0x7faa17bbffff)’ isn’t the result I expected, so I think there must be something wrong and I use the ldd command to check the dependencies:

$ ldd fibonacci => (0x00007fffcd1ba000) => /lib64/ (0x00000031edc00000) => /lib64/ (0x00000031ed800000) => /lib64/ (0x00000031ee400000) => /lib64/ (0x00000031ef000000) => /home/admin/jianzhang.zj/oprofile-0.9.9-install//lib/oprofile/ (0x00007fb835b86000) => /lib64/ (0x00000031ee000000) => /usr/lib64/ (0x00000031f3000000) => /lib64/ (0x00000031f0800000) => /lib64/ (0x00000031ed400000)
/lib64/ (0x00000031ed000000) => /home/admin/jianzhang.zj/binutils-2.24-install/lib/ (0x00007fb83587b000) => /home/admin/jianzhang.zj/binutils-2.24-install/lib/ (0x00007fb83563e000)

$ ldd -u fibonacci
Unused direct dependencies:


can anyone tell me how to profile the llvm JITed code or which step was wrong ?

thanks very much.