善用工具
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