https://github.com/gperftools/gperftools
https://gperftools.github.io/gperftools/cpuprofile.html
yum install libunwind
yum install libunwind-devel
yum install graphviz
编译时 -lprofiler 运行找不到 profiler 时,export LD_LIBRARY_PATH=/usr/local/lib/ 默认装这下面
There are several alternatives to actually turn on CPU profiling for a given run of an executable:
Define the environment variable CPUPROFILE to the filename to dump the profile to. For instance, if you had a version of /bin/ls
that had been linked against libprofiler, you could run:
% env CPUPROFILE=ls.prof /bin/ls
In addition to defining the environment variable CPUPROFILE you can also define CPUPROFILESIGNAL. This allows profiling to be controlled via the signal number that you specify. The signal number must be unused by the program under normal operation. Internally it acts as a switch, triggered by the signal, which is off by default. For instance, if you had a copy of /bin/chrome
that had been been linked against libprofiler, you could run:
% env CPUPROFILE=chrome.prof CPUPROFILESIGNAL=12 /bin/chrome &
You can then trigger profiling to start:
% killall -12 chrome
Then after a period of time you can tell it to stop which will generate the profile:
% killall -12 chrome
In your code, bracket the code you want profiled in calls to ProfilerStart()
and ProfilerStop()
. (These functions are declared in
.) ProfilerStart()
will take the profile-filename as an argument.
分析:
pprof ./demo my.prof > profile.txt
pprof --text ./demo my.prof > profile.txt
pprof --pdf ./demo my.prof > profile.pdf