【善用工具】程序性能分析Gperftools初探(libwind+pprof+Kcachegrind)

本文介绍了如何使用Gperftools进行程序性能分析,包括安装libunwind、gperftools及其图形分析工具Graphviz,以及如何使用pprof和Kcachegrind进行CPU热点函数分析。通过示例展示了如何处理程序执行时间短和服务器程序的性能测量问题。
摘要由CSDN通过智能技术生成

善用工具
http://blog.csdn.net/aganlengzi/article/details/62893533
本文主要试用的gperftool相关介绍可见:https://github.com/gperftools/gperftools/wiki

gperftools性能分析通过抽样方法完成,默认是1秒100个样本,so,一个样本是10毫秒,即时间单位是10毫秒.
之所以要在这里特别说明,是因为需要注意到:如果程序运行时间不到10ms,那么得到的结果可能会和开始执行的时候不同.

0.系统信息

sjc@sjc-pc:~/baidu/gperftool/test$ uname -a
Linux sjc-pc 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

还有就是处理器是amdx2…

1.安装文件

.
├── gperftools-2.0
├── gperftools-2.0.tar.gz
├── libunwind-0.99-beta
├── libunwind-0.99-beta.tar.gz
├── readme.txt
└── test

下载:http://pan.baidu.com/s/1jIFl1qu

2.安装过程:

2.1.gperftools在64位系统上需要unwind库的支持,所以需要先安装libunwind,而且对版本有了要求:libunwind-0.99-beta

./configure --prefix=/home/sjc/tools/gperftools -CFLAGS=-U_FORTIFY_SOURCE

NOTE: In Ubuntu 8.10 and later versions, -D_FORTIFY_SOURCE=2 is set by default, and is activated when -O is set to 2 or higher. This enables additional compile-time and run-time checks for several libc functions. To disable, specify either -U_FORTIFY_SOURCE or -D_FORTIFY_SOURCE=0.D_FORTIFY_SOURCE的级别设置越高,对overflow等的检查也更严格.

sudo make
sudo make install

以上,libunwind库会被安装到prefix指定的路径下.

2.2.编译安装gperftools-2.0:

NOTE: 之所以安装版本2.0而不是目前最新的2.5,是因为在编译2.5版本的时候,总是会出现:
undefined "_ULx86_64_getcontext"之类错误,分析后认为,gperftools库需要libunwind提供一些符号的支持,
但是在libunwind中不存在这些符号,这就尴尬了,这种尴尬的原因我猜想是2.5版本是对应更高的unwind库版本的(未验证,也可能和我自己的平台环境有关系).
顺着这个思路,将gperftool的版本降为2.0版本.

./configure --prefix=/home/sjc/tools/gperftools
sudo make

NOTE: 如果错误显示:
In function ‘void ListerThread(ListerParams*)’:
error: invalid conversion from ‘void ()(int, siginfo_t, void*)’ to ‘void ()(int, siginfo, void*)’ [-fpermissive]
修改linuxthreads.cc:static void SignalHandler(int signum, siginfo_t *si, void *data) {
为 static void SignalHandler(int signum, siginfo *si, void *data) {
编译可过.

sudo make install

NOTE: 之前忘了执行install[捂脸]第二天早上来还手动将需要的头文件和lib复制到prefix目录下,也是醉了

2.3.为了图形分析还需要安装Graphviz
用于绘制DOT语言脚本描述的图形,gperftools依靠此工具生成图形分析结果。

sudo apt-get install graphviz

以上步骤安装成功后:

sjc@sjc-pc:~/tools/gperftools$ tree -L 2
.
├── bin
│   └── pprof
├── include
│   ├── google
│   ├── gperftools
│   ├── libunwind-common.h
│   ├── libunwind-dynamic.h
│   ├── libunwind.h
│   ├── libunwind-ptrace.h
│   ├── libunwind-x86_64.h
│   └── unwind.h
├── lib
│   ├── libprofiler.a
│   ├── libprofiler.la
│   ├── libprofiler.so -> libprofiler.so.0.3.0
│   ├── libprofiler.so.0 -> libprofiler.so.0.3.0
│   ├── libprofiler.so.0.3.0
│   ├── libtcmalloc.a
│   ├── libtcmalloc_and_profiler.a
│   ├── libtcmalloc_and_profiler.la
│   ├── libtcmalloc_and_profiler.so -> libtcmalloc_and_profiler.so.4.1.0
│   ├── libtcmalloc_and_profiler
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值