性能测试工具gperftools使用

时间:2019-10-22
本文章向大家介绍性能测试工具gperftools使用,主要包括性能测试工具gperftools使用使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

https://blog.csdn.net/10km/article/details/83820080

https://blog.51cto.com/wulingdong/2043898

https://www.jianshu.com/p/1611205f2c01

需要的组件:

编译安装gperftools

从https://github.com/gperftools/gperftools/releases下载最新版本的gperftools源码包
解压到/usr/local/src目录
cd 解压源码目录

./autogen.sh
./configure
make -j6
make install

可视化:

graphviz: https://graphviz.gitlab.io/_pages/Download/Download_source.html

webdot: https://graphviz.gitlab.io/_pages/Download/Download_source.html

转PDF: ghostscript:https://www.ghostscript.com/download/gsdnld.html

示例代码:

#include <gperftools/profiler.h>
#include <stdlib.h>

void f()
{
    int i;
    for (i=0; i<1024*1024; ++i)
    {
        char *p = (char*)malloc(1024*1024*120);
        free(p);
    }
}

void fun1() {
  f();
}
void fun2() {
  f();
}

int main()
{
    ProfilerStart("test.prof");//开启性能分析
    fun1();
    fun2();
    ProfilerStop();//停止性能分析
    return 0;
}

编译: 

g++ test_pprof1.cpp -o test  -ltcmalloc -lprofiler

执行:

./test

 生成了test.prof文件

查看性能报告:text版

pprof ./test test.prof --text

可见如下结果:

生成性能报告:PDF

pprof ./test test.prof --pdf > test.pdf

原文地址:https://www.cnblogs.com/gnivor/p/11719958.html