I have found several conflicting answers over this topic. This blog post requires libuwind, but that doesn't work on Mac OS X. I included #include <google/profiler.h>
in my code, however my compiler (g++) could not find the library. I installed gperftools
via homebrew. In addition, I found this stackoverflow question showing this:
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 ...
Running that command (without any of the prior steps) gets me this:
[hidden]$ pprof --text ./a.out cpu.profile
Using remote profile at ./a.out.
Failed to get the number of symbols from http://cpu.profile/pprof/symbol
Why does it try to access an internet site on my machine and a local file on his/hers?
Attempting to link lib profiler as a dry run with g++ gets me:
[hidden]$ g++ -l libprofiler
ld: library not found for -llibprofiler
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have looked at the man pages, the help option text, the official online guide, blog posts, and many other sources.
I am so confused right now. Can someone help me use gperftools?
The result of my conversation with @osgx was this script. I tried to clean it up a bit. It likely contains quite a few unnecessary options too.
-lprofiler
to the link-time step for your executable. (It's also probably possible to add in the profiler at run-time usingLD_PRELOAD
, but this isn't necessarily recommended.)") Did you have cpu.profile file? – Lysol