|
Mailed to http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20090629/079752.html
OProfile provides a library to tell it about JIT output, described at http://oprofile.sourceforge.net/doc/devel/jit-interface.html. This patch tells OProfile about function ranges, but not line numbers. It adds a --with-oprofile=<prefix> flag to configure, but I don't know how to do the equivalent to cmake.
Problems:
1. Because oprofile installs its libraries to <prefix>/lib/oprofile, we need an -rpath option to let the loader find them. We could probably link the oprofile library statically to avoid this.
2. llvm-config doesn't include the required -L and -rpath flags in its --ldflags output, even though it includes -lopagent.
3. cmake support is missing, as mentioned above.
I've tested this by running the following fib.c under lli. Let me know if you can think of an automated way to test it.
----------------
$ cat fib.c
/* Use this to test oprofile support. Some useful command lines are:
# To get per-app stats:
sudo opcontrol --separate=library
clang -g fib.c -o fib
sudo opcontrol --reset; sudo opcontrol --start-daemon; sudo opcontrol --start; ./fib; sudo opcontrol --stop
opreport -g -d -l ./fib|less
clang -g fib.c -c -emit-llvm -o fib.bc
sudo opcontrol --reset; sudo opcontrol --start-daemon; sudo opcontrol --start; lli fib.bc; sudo opcontrol --stop
opreport -g -d -l `which lli`|less
*/
#include <stdio.h>
int fib_left(int);
int fib_right(int);
int fib_left(int i) {
if (i < 2)
return 1;
return fib_left(i-1) + fib_right(i-2);
}
int fib_right(int i) {
if (i < 2)
return 1;
return fib_left(i-1) + fib_right(i-2);
}
int fib(int i) {
if (i < 2)
return 1;
return fib_left(i-1) + fib_right(i-2);
}
int main() {
int i = 40;
printf("fib(%d) == %d\n", i, fib(i));
}
$
--------------
Before:
$ opreport -l ~/opensource/llvm/trunk/dbg/Debug/bin/lli
CPU: Core 2, speed 1998 MHz (estimated)
Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (Unhalted core cycles) count 100000
samples % image name symbol name
48182 98.9729 anon (tgid:19412 range:0x7f12ccaab000-0x7f12cdaab000) anon (tgid:19412 range:0x7f12ccaab000-0x7f12cdaab000)
11 0.0226 libstdc++.so.6.0.9 /usr/lib/libstdc++.so.6.0.9
10 0.0205 lli llvm::MachineOperand::isReg() const
...
After:
$ opreport -l `which lli`
CPU: Core 2, speed 1998 MHz (estimated)
Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (Unhalted core cycles) count 100000
samples % image name symbol name
24565 60.7308 19814.jo fib_left
15365 37.9861 19814.jo fib_right
22 0.0544 ld-2.7.so do_lookup_x
10 0.0247 lli llvm::MachineOperand::isReg() const
8 0.0198 ld-2.7.so _dl_relocate_object
8 0.0198 lli std::vector<llvm::MachineOperand, std::allocator<llvm::MachineOperand> >::size() const
...
|