性能測試工具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

可能遇到的問題:gperftools Error: substr outside of string at /usr/local/bin/pprof line XXXX

https://stackoverflow.com/questions/32508296/gperftools-error-substr-outside-of-string-at-usr-local-bin-pprof-line-3618?lq=1

 

可視化:

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM