gperftools定位CPU热点函数

1、下载及安装libunwind 

下载地址: http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz 

安装:./configure CFLAGS=-U_FORTRIFY_SOURCE ; make -j8 ; make install

2、下载及安装gperftools 

git地址:https://github.com/gperftools/gperftools 

安装: ./configure ; make -j8 ; make install

或者:yum install gperftools gperftools-devel

3、使用方法 

参考:https://dirtysalt.github.io/gperftools.html#orgheadline4 

举例:

LD_PRELOAD="/usr/local/lib/libprofiler.so" CPUPROFILE=cpu_perf.prof CPUPROFILE_FREQUENCY=100 ./exe

运行完成后会在当前目录下生成cpu_perf.prof文件,结合pprof工具(gperftools/bin)可生成txt或pdf等,例如:

pprof --pdf ./test cpu_perf.prof > cpu_perf.pdf

pprof --txt ./test cpu_perf.prof > cpu_perf.txt

你可能感兴趣的:(gperftools定位CPU热点函数)