使用 gperftools 分析 cpp 程序性能

首先从这里,https://code.google.com/p/gper…,下载 gperftools-2.1.tar.gz

接下来的操作教程主要参看这篇文章,http://www.searchtb.com/2012/1…,Google CPU Profiler使用指南及小工具,已经写的很好了,其中需要注意的问题有几个:

  1. 原文的 Makefile 没有排版,需要自己去 tab 缩进,不然在 make 的时候会报错
  2. 在运行起来的时候报错,链接失败,参看这里,http://blog.csdn.net/dumeifang…

    在linux下运行程序时,发现了error while loading shared libraries这种错误,一时间不知道解决办法,在网上搜索,终于解决了:

    ./tests: error while loading shared libraries: xxx.so.0:cannot open shared object file: No such file or directory
    出现这类错误表示,系统不知道xxx.so放在哪个目录下,这时候就要在/etc/ld.so.conf中加入xxx.so所在的目录。

    一般而言,有很多的so会存放在/usr/local/lib这个目录底下,去这个目录底下找,果然发现自己所需要的.so文件。

    所以,在/etc/ld.so.conf中加入/usr/local/lib这一行,保存之后,再运行:/sbin/ldconfig –v更新一下配置即可。

  3. 在使用 pprof 进行结果输出的时候,需要注意,pprof 这个工具是存放在安装目录下的 tools/gperftoools/bin/pprof 这里的

基本就没什么问题了,然后可以得到下图

QQ截图20130819173754

=================================================

2013-08-21 09:17:474 update 另外,针对文中提到的动态链接库和 dlopen 的方式,我发现如果进程是被 killall 命令结束的话,那么是无法生成记录文件的,这个问题需要注意处理

Leave a Reply

Your email address will not be published. Required fields are marked *