gperftools 是 google 开源的一组套件,提供了高性能的、支持多线程的 malloc 实现,以及一组优秀的性能分析工具。
从 gperftools github 官网上下载最新版本的源码包:
wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.10/gperftools-2.10.tar.gz
tar -zxv -f gperftools-2.10.tar.gz
cd gperftools-2.10
./configure
命令结束执行后出现一个报错:
configure: WARNING: No frame pointers and no libunwind. Using experimental backtrace capturing via libgcc. Expect crashy cpu profiler.
这是因为没有安装 libunwind
。这里直接使用 yum 的方式安装:
yum install libunwind-devel
再次执行 ./configure
,命令执行成功。
执行如下两个命令,进行编译并安装:
make
sudo make install
最后执行 ldconfig
更新动态库文件
执行如下命令,确认 gperftools 安装成功
[root@36eab gperftools-2.10]# pprof --version
pprof (part of gperftools 2.0)
Copyright 1998-2007 Google Inc.
This is BSD licensed software; see the source for copying conditions
and license information.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
123456789
#include
#include
g++ -std=c++11 main.cpp -o main -lprofiler
env CPUPROFILE=./profile.prof ./main
profile.prof为生成的文件名
pprof ./main ./profile.prof --svg > svg.svg
./main为上面的可执行程序
在浏览器中打开svg.svg文件即可