我已经安装了 gperftools-2.0,但是我无法获取 cpu profile 统计信息
以下是我获取统计信息的步骤:
- 安装 gperftools tar -xzvfj gperftools-2.0.tar.gz
2.编辑cpp文件test.cpp
#include <stdio.h>
#include <gperftools/profiler.h>
int main()
{
ProfilerStart("test.prof");
for (int i = 0; i<100; i++)
{
printf("hello world!");
}
ProfilerStop();
return 0;
}
编译 g++ test.cpp -o 测试 -O0 -I/usr/local/include/-L/usr/local/lib/-lprofiler
运行 ./测试
报告 pprof ./test --text test.prof
其输出是: 使用本地文件 ./test. 使用本地文件 test.prof。
我的步骤有什么问题?
最佳答案
你只需要你的程序运行更长的时间,因为谷歌分析器只是每隔一段时间更新一次 CPU 统计信息。重置“CPUPROFILE_FREQUENCY”或“CPUPROFILE_REALTIME”值可以更改此间隔时间。
关于c++ - 我已经安装了 gperftools-2.0,但是我无法获取 cpu profile 统计信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10313357/