Ubuntu 使用perfTools进行软件的性能分析

Ubuntu 使用perfTools进行软件的性能分析,第1张

Ubuntu 使用perfTools进行软件的性能分析

Ubuntu 使用perfTools进行软件的性能分析

1.下载

http://download.savannah.gnu.org/releases/libunwind/
https://sourceforge.net/projects/gperftools.mirror/
sudo apt-get install graphviz

  1. 在/usr/local/下解压
    sudo tar -zxvf libunwind-1.6.0-rc2.tar.gz
    sudo tar -zxvf cp /home/hlx/Downloads/gperftools-2.9.1.tar.gz

  2. cd 进入解压后的目录

  3. 安装库
    ./configure
    sudo make
    sudo make install

  4. pprof 所在目录加入环境变量

  5. 新建qt工程,链接库
    LIBS +=-lprofiler
    LIBS +=-lunwind
    main.cpp如下

  6. 查看目录下生成的的.prof文件
    pprof ./untitled a.prof –web

#include 
#include 
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();
    fun1();
    fun2();
    ProfilerStop();//停止性能分析
    return 0;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5351237.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-09
下一篇 2022-12-09

发表评论

登录后才能评论

评论列表(0条)

保存