如何使用Google perftools优化程序


Google Perftool 是一个开源的Performance工具集,包括了高效的malloc,内存检查工具,以及性能测试工具。本文主要介绍它的性能测试工具。该工具的设计思路和GNU Profiler是一致的,都是在被测程序中链接一个库,然后运行程序,收集profiler结果最后分析。可以把Google CPU Profiler看作GNU Profiler的一个更好的替代工具。

1. 安装

在64位系统中,安装该工具还需要安装另外一个库libunwind,这是因为系统自带的堆栈解旋库会导致profiler无法正常工作,而开源库libunwind解决了这个问题。所以如果我们在64位linux下安装,需要安装libunwind:

./configure --prefix=/home/work/local/libunwind-0.99 --enable-shared=no

安装google-perftools:

./configure --prefix=/home/work/local/google-perftools-1.7 CPPFLAGS=-I/home/work/local/libunwind-0.99/include/ LDFLAGS="-lunwind -lunwind-x86_64 -L/home/work/local/libunwind-0.99/lib/" --enable-shared=no


2. 使用:

makefile中加入:

LDLIBS += -lunwind -lprofiler
LDFLAGS += /home/work/local/google-perftools-1.7/lib
LDFLAGS += /home/work/local/libunwind-0.99/lib


3. 修改程序:

 


成功案例



中国科学院
嘉实基金
北京排水集团
智泓科技
中国科学院
嘉实基金
北京排水集团
智泓科技