工作中有碰到进程内存泄露问题,记录一下gperftools这个工具的使用方法。
首先是安装,64位系统gperftools的安装是需要unwind库支持,所以安装unwind,以及gperftools。在官网下载unwind版本和gperftools版本。自己用的是unwind-0.99-beta和gperftools-2.5版本的安装包。
unwind的安装比较简单,也没遇到啥问题。
./configure --prefix=要安装的路径
make
make install
gperftools编译时要依赖unwind库。
./configure --prefix=要安装的路径 LDFLAGS=-L安装unwind路径/lib CPPFLAGS=-I安装unwind路径/include
make
make install
这样需要的工具就安装好了。
需要生成图像分析的话还需要graphviz,下载地址https://graphviz.gitlab.io/pub/graphviz/stable/SOURCES/graphviz.tar.gz。
当然如果不是内网的开发环境,都可以用sudo apt-get install graphviz进行安装。
gperftools包括有内存监控工具heap-profiler,内存泄露工具heap-checker,cpu性能分析工具cpu-profiler。heap-checker是常用的用法是检测程序整个进程生命周期的内存泄露,项目编译