GooglePerformance Tools简介

GooglePerformance Tools简介

1、安装

a) 安装libunwind

libunwind是一个用于解析程序调用栈的C++库,由于glibc内建的栈回滚功能在64位系统上有bug,因此googleperformance tools建议使用libunwind

下载libunwind-0.99-beta.tar.gz

cd $HOME

tarxzvf libunwind-0.99-beta.tar.gz

mkdir libunwind-0.99-beta-build

cd libunwind-0.99-beta

./configure -prefix=$HOME/libunwind-0.99-beta-build

b) 安装Google PerformanceTools

注意:如果在系统目录中找不到libunwindgoogle performance tools将默认使用glibc的内建功能,因此我们需要手动设置libunwind的安装目录。

下载google-perftools-1.6.tar.gz

cd $HOME

tar xzvf google-perftools-1.6.tar.gz

mkdir google-perftools-1.6-build

cd google-perftools-1.6

./configure -prefix=$HOME/ google-perftools-1.6-build

CPPFLAGS=-I$HOME/libunwind-0.99-beta-build/include

LDFLAGS=-L$HOME/libunwind-0.99-beta-build/lib

make && make install

2、用法

参考官方文档

这里有两点想突出介绍下,一个是对动态库的支持,一个对动态profiler功能的支持。

Heap Checker:

gcc [...] -o myprogram -ltcmalloc

HEAPCHECK=normal ./myprogram

Heap Profiler:

gcc [...] -o myprogram -ltcmalloc

HEAPPROFILE=/tmp/netheap ./myprogram

Cpu Profiler:

gcc [...] -o myprogram -lprofiler

CPUPROFILE=/tmp/profile ./myprogram

g++ -g -O0 -o main main.cpp -lprofiler -L/home/google-perftools-1.6-build/lib

CPUPROFILE=perf.out./main

pprof --text./main  ./perf.out

此外还支持动态加载库。

使用步骤

google cpuprofiler usage

1) Link your executable with -lprofiler

2) export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

3) Run your executable with the CPUPROFILE environment var set:

$ CPUPROFILE=/tmp/prof.out <path/to/binary> [binary args]

4) Run pprof to analyze the CPU usage

$ pprof  --text --cum <path/to/binary> /tmp/prof.out    # -pg-like text output

$ pprof --gv <path/to/binary>     /tmp/prof.out     # really cool graphical output

3、结果分析

Text mode has lines of output that look like this:

14   2.1%  17.2%       58   8.7% std::_Rb_tree::find

1. Number of profiling samples in this function

第一列:本函数内sample的数目,即除去该函数调用的其它函数之后自身的sample数目

2. Percentage of profiling samples in this function

第二列:本函数内sample的数目占总sample的比例,即除去该函数调用的其它函数之后的自身sample占总sample的比例

3. Percentage of profiling samples in the functions printed so far

第三列:是第二列比例的累加

4. Number of profiling samples in this function and its callees

第四列:本函数内所有sample的数目,即包含自身及它所调用的其它函数的sample总数

5. Percentage of profiling samples in this function and its callees

第五列:本函数内所有sample的数目占总数目的比例,即包含自身及它所调用的其它函数的sample总数占总数目的比例

6. Function name

第六列:函数名,按照第五列的大小排序,缺点是不能直观的看到函数之间的调用关系及开销,因为一个函数可能被多个函数调用,这个地方显示的是该函数总的sample数目。

原文

[1]http://www.cnblogs.com/likwo/archive/2012/12/20/2826988.html

[2]http://code.google.com/p/gperftools/wiki/GooglePerformanceTools?redir=1

[3]http://wenku.baidu.com/view/84324701a6c30c2259019e35.html

原文地址:https://www.cnblogs.com/mydomain/p/2956617.html