I am trying to profile some C++ programs on MacOSX. So I built google-perftools
, wrote a program, compiled using MacPorts g++ 4.7, with -g
compiler flag, and linked to libprofiler
. Then I ran:
CPUPROFILE=cpu.profile ./a.out
Then I ran pprof to generate the output:
[hidden ~]$ pprof --text ./a.out cpu.profile
Using local file ./a.out.
Using local file cpu.profile.
Removing __sigtramp from all stack traces.
Total: 282 samples
107 37.9% 37.9% 107 37.9% 0x000000010d72229e
16 5.7% 43.6% 16 5.7% 0x000000010d721a5f
12 4.3% 47.9% 12 4.3% 0x000000010d721de8
11 3.9% 51.8% 11 3.9% 0x000000010d721a4e
9 3.2% 55.0% 9 3.2% 0x000000010d721e13
8 2.8% 57.8% 8 2.8% 0x000000010d721a64
7 2.5% 60.3% 7 2.5% 0x000000010d7222f0
6 2.1% 62.4% 6 2.1% 0x000000010d721a4c
6 2.1% 64.5% 6 2.1% 0x000000010d721b1f
6 2.1% 66.7% 6 2.1% 0x000000010d721e0c
5 1.8% 68.4% 5 1.8% 0x000000010d721fba
......
It looks like the perftools don't convert the addresses to function names.
Does anyone know what I am missing here? What should I do to let the profiler generate the correct result.
EDIT: More information: it is not a problem of pprof or google-perftools, but more something like gcc or macosx, because Instrument.app also shows addresses instead of line numbers. I am not familiar with how debug symbols work under Mac OS X, so I would rather think it as my missing something here, instead of being bugs in gcc or Mac OS X. I wonder whether anyone can provide some hints on how debug info works for Mac OS X.
gperftools is a set of tools for performance profiling and memory checking. One of the main advantages of the CPU profiler is a very nice graphical output, low overhead and very simple use (the profiled application doesn't require any recompilation, the profiling is enabled by simply preloading the profiler's library).
Where is your libprofiler. so. 0 ? It should be installed into /usr/local/lib or /usr/lib .
This seems to be related to the address space layout randomization (ASLR) introduced in OS X 10.5
I've filed issue #562 on the gperftools issue tracker. You can disable ASLR by passing -Wl,-no_pie
.
Also, if you're not bound to use gperftools
, Instruments
(comes with Xcode
) is worth a try.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With