Google Performance Tools

安装

1
sudo apt install google-perftools libgoogle-perftools-dev

使用

#include <gperftools/profiler.h>
-lprofiler

1
2
3
4
5
6
7
8
9
#include <gperftools/profiler.h>

int fun()
{
ProfilerStart("xxx.prof");
// code
ProfilerStop();
return 0;
}
1
2
3
4
# 分析结果
google-pprof --pdf xxx xxx.prof > xxx.pdf
google-pprof --gif xxx xxx.prof > xxx.gif
google-pprof --text xxx xxx.prof > xxx.text

问题

  1. 程序运行输出PROFILE: interrupts/evictions/bytes = 0/0/64
    这种情况可能是程序占用 CPU 太低了,导致没有分析出结果,可以写个循环验证试试。

  2. 执行google-pprof输出如下结果,原因同 1

    1
    2
    3
    # Using local file hotplug.
    # Using local file test.prof.
    # No nodes to print

参考


Google Performance Tools
https://laplac2.github.io/tools/gperftools/
作者
Laplace
发布于
2023年12月4日
许可协议