1、安装
您可以在 google-perftools 的网站 (http://code.google.com/p/google-perftools/downloads/list) 上下载最新版的安装包
2、编译与运行
void bar()
{
for(int i = 0; i < 1000; i++)
{
;
}
}
void foo()
{
for(int i = 0; i < 100000; i++)
{
bar();
}
}
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <gperftools/profiler.h>
#include "DebugData.h"
int main(int argc, char * argv[])
{
char * ptrChar = NULL;
DEBUG_PRINTF( "111111111111........");
ProfilerStart("myprof.txt");
bar();
foo();
ProfilerStop();
}
编译参数增加 -lprofiler -L$(LIB_PROFILER_DIR)
3、结果分析
执行 ./t 会生成 ./myprof.txt
分析结果:
pprof --tools=/usr/bin/ --pdf ./t myprof.txt > myprof.pdf
其中 --tools=/usr/bin/ 非常重要; 不加的话有可能不显示函数名,而仅仅显示地址(为了这问题 折腾了我好几天,好不容易查到资料把问题搞定)

最后
以上就是怕孤独蛋挞最近收集整理的关于pprof 的使用的全部内容,更多相关pprof内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复