gprof 没有输出

2024-01-22

我正在尝试使用 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

就是这样。


如果您使用 gcc 6,您很可能会遇到this https://lists.gnu.org/archive/html/bug-binutils/2017-02/msg00262.htmlbug(请注意,该 bug 并非特定于 Debian,而是取决于 gcc 的构建方式)。解决方法是使用“-no-pie”选项进行编译,该选项禁用与位置无关的代码生成。

This https://stackoverflow.com/questions/2463150/what-is-the-fpie-option-for-position-independent-executables-in-gcc-and-ld如果您想了解更多有关 PIE 的信息,这是一个好的开始。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

gprof 没有输出 的相关文章

随机推荐