gprof vs cachegrind profiles

ev-*_*-br 11 c++ optimization profiling valgrind gprof

在尝试优化代码时,我对由kcachegrdind和生成的配置文件的差异感到有些困惑gprof.具体来说,如果我使用gprof(使用-pg交换机编译等),我有这个:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 89.62      3.71     3.71   204626     0.02     0.02  objR<true>::R_impl(std::vector<coords_t, std::allocator<coords_t> > const&, std::vector<unsigned long, std::allocator<unsigned long> > const&) const
  5.56      3.94     0.23 18018180     0.00     0.00  W2(coords_t const&, coords_t const&)
  3.87      4.10     0.16   200202     0.00     0.00  build_matrix(std::vector<coords_t, std::allocator<coords_t> > const&)
  0.24      4.11     0.01   400406     0.00     0.00  std::vector<double, std::allocator<double> >::vector(std::vector<double, std::allocator<double> > const&)
  0.24      4.12     0.01   100000     0.00     0.00  Wrat(std::vector<coords_t, std::allocator<coords_t> > const&, std::vector<coords_t, std::allocator<coords_t> > const&)
  0.24      4.13     0.01        9     1.11     1.11  std::vector<short, std::allocator<short> >* std::__uninitialized_copy_a<__gnu_cxx::__normal_iterator<std::vector<short, std::alloca
Run Code Online (Sandbox Code Playgroud)

这似乎表明我不需要在任何地方寻找,但是 ::R_impl(...)

同时,如果我在没有-pg开关的情况下编译并运行valgrind --tool=callgrind ./a.out,我会有一些不同的东西:这是kcachegrind输出的截图

在此输入图像描述

如果我解释这个正确的,这似乎表明,::R_impl(...)只需要时间的约50%,而另一半则是线性代数花(Wrat(...),eigenvalues和底层的LAPACK通话),低于一路下滑的gprof曲线.

我理解gprofcachegrind使用不同的技术,如果他们的结果有所不同,我不会打扰.但在这里,它看起来非常不同,我不知道如何解释这些.任何想法或建议?

小智 12

您正在查看错误的列.你必须查看kcachegrind输出中的第二列,名为"self".这是特定子程序花费的时间,而不考虑其子项.第一列有累积时间(它等于主要机器时间的100%)并且它不具备信息(在我看来).

请注意,从kcachegrind的输出中可以看出,进程的总时间为53.64秒,而在子程序"R_impl"中花费的时间为46.72秒,占总时间的87%.所以gprof和kcachegrind几乎完全一致.


Pau*_*l R 6

gprof是一个仪表化的分析器,callgrind是一个采样分析器.使用检测的分析器,您可以获得每个功能进入和退出的开销,这可能会使配置文件发生偏斜,特别是如果您具有相对较小的功能,这些功能被多次调用.采样分析器往往更准确 - 它们会略微降低整个程序的执行速度,但这往往会对所有功能产生相同的相对影响.

尝试的免费30天的评估从RotateRight放大 -我怀疑它会给你同意哪个更具有轮廓callgrindgprof.

  • 什么??gprof 正在采样(它将每 10 或 1 毫秒对 PC 采样一次,以获得输出中的 %% 计数),而 cachegrind/callgrind 正在检测(它们使用 valgrind 动态检测代码并通过检测统计数据进行计数 - 在基本块层)。Cachegrind/callgrind 甚至模拟分析器,因为测量不是实时的,而是虚拟事件(模拟缓存层次结构、模拟分支预测、不带任何停顿获取的指令) (2认同)