我正在尝试使用 gprof 来分析我正在开发的一些数字代码,但 gprof 似乎无法从我的程序中收集数据。这是我的命令行:
g++ -Wall -O3 -g -pg -o fftw_test fftw_test.cpp -lfftw3 -lfftw3_threads -lm && ./fftw_test
gmon.out 文件已创建,但似乎没有数据。当我跑步时
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 例程。它具有计算某些复数系数的函数、将输入数据乘以这些系数的函数等等。
编辑:包括示例代码和结果。
#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
Result:
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
就是这样。