gperftools-2.5.93

来源:互联网 发布:yy免费头像源码和制作 编辑:程序博客网 时间:2024/06/06 21:29


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/ 默认装这下面


Running the Code

There are several alternatives to actually turn on CPU profiling for a given run of an executable:

  1. 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
  2. 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
  3. In your code, bracket the code you want profiled in calls to ProfilerStart() andProfilerStop(). (These functions are declared in <gperftools/profiler.h>.)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

原创粉丝点击