zero91 / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

CPU Profiler documentation needs to be updated with respect to linking and running #412

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The documentation could be much more clear with respect to linking and running 
the cpu profiler. Upon first glance it isn't immediately obvious that 
-lprofiler actually behaves quite differently depending on whether this  is 
linked as a shared or static library.

If you link your executable against libprofiler.a it doesn't actually do 
anything unless you are explicitly including google/profiler.h and manually 
enabling profiling using the API. Otherwise, no symbols are actually referenced 
in the library and the resulting executable has no profiler code in it. You can 
also verify this with 'nm <executable> | grep -i profiler'.

If you want to automatically enable profiling, what you need to do is link your 
executable against libprofiler.so. This causes the profiler to get pulled in to 
the resulting executable and start in the presence of the CPUPROFILE 
environment variable.

Something similar to this explanation should live in the documentation.

Original issue reported on code.google.com by chapp...@gmail.com on 3 Mar 2012 at 4:48

GoogleCodeExporter commented 9 years ago
My understanding is that you can pass -Wl,--undefined=ProfilerStart to gcc 
causing it to link-in libprofiler.a.

Original comment by alkondratenko on 15 Sep 2013 at 12:17

GoogleCodeExporter commented 9 years ago
http://stackoverflow.com/questions/14116420/how-to-force-gcc-to-link-an-unused-s
tatic-library

Original comment by xingming...@gmail.com on 2 Mar 2015 at 9:34