gprof 没有输出 [英] gprof gives no output
问题描述
我正在尝试使用 gprof 来分析我正在开发的一些数字代码,但是 gprof 似乎无法从我的程序中收集数据.这是我的命令行:
I am trying to use gprof to profile some numerical code I am developing, but gprof seems to fail to collect data from my program. Here is my command line:
g++ -Wall -O3 -g -pg -o fftw_test fftw_test.cpp -lfftw3 -lfftw3_threads -lm && ./fftw_test
gmon.out 文件已创建,但似乎没有数据.当我跑
The gmon.out file is created, but it seems to have no data. When i run
gprof -b fftw_test gmon.out > gprof.out
我得到的是
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
Call graph
granularity: each sample hit covers 2 byte(s) no time propagated
index % time self children called name
Index by function name
有什么见解吗?
代码做了很多事情,它不只是调用 FFTW 例程.它具有计算某些复数系数的函数、将输入数据乘以这些系数的函数等.
The code does a lot of stuff, it does not simply call FFTW routines. It has functions that compute certain complex coefficients, functions that multiply input data by these coefficients, and so on.
编辑.:包括示例代码和结果.
Edit.: Including example code and results.
#include <cstdlib>
#include <ctime>
int main()
{
std::srand( std::time( 0 ) );
double sum = 0.0;
for ( int i = 0; i < RAND_MAX; ++i )
sum += std::rand() / ( double ) RAND_MAX;
std::cout << sum << '\n';
return 0;
}
命令行:
$ g++ -Wall -O3 -g -pg -o gprof_test gprof_test.cpp && ./gprof_test
1.07374e+09
$ gprof -b gprof_test gmon.out > gprof.out
$ cat gprof.out
结果:
Flat profile:
Each sample counts as 0.01 seconds.
no time accumulated
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
Call graph
granularity: each sample hit covers 2 byte(s) no time propagated
index % time self children called name
Index by function name
就是这样.
推荐答案
如果您使用 gcc 6,您很可能会遇到 this 错误(请注意,该错误并非特定于 Debian,而是取决于 gcc 的构建方式).一种解决方法是使用 `-no-pie' 选项进行编译,该选项会禁用与位置无关的代码生成.
If you're using gcc 6, you're most likely running into this bug (note that the bug is not specific to Debian but depends on how gcc was built). A workaround is simply to compile using the `-no-pie' option which disables position-independent code generation.
这篇关于gprof 没有输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!