使用google-perftools进行C/C++性能分析
目录
安装libunwind
wget https://github.com/libunwind/libunwind/releases/download/v1.3.0/libunwind-1.3.0.tar.gz --no-check-certificate tar -xvf libunwind-1.3.0.tar.gz cd libunwind-1.3.0 ./configure make & make install
安装perftool
git clone https://github.com/gperftools/gperftools cd gperftools/ sh autogen.sh ./configure make & make install ln -s /usr/local/lib/libprofiler.so.0 /usr/lib64/libprofiler.so.0 (64位机,32位目录在/usr/lib/)
安装graphviz
yum -y install graphviz
修改编译选项,增加“-L/usr/local/lib -lprofiler”
在性能评测点前运行:ProfilerStart(“MyProfile”)
在性能评测点后运行:ProfilerStop()
以上两个命令,可以直接写在代码里,也可以通过gdb call
目录检查,发现:MyProfile文件
pprof –svg ./myapp MyProfile > profile.svg
其他选项可以直接执行pprof查看,可通过多种形式查看报告,我们这里选择svg,svg可使用浏览器打开