【问题标题】:How to understand percents in perf?如何理解 perf 中的百分比?
【发布时间】:2023-02-04 02:37:03
【问题描述】:

考虑以下应用程序。

#include <cmath>

void foo()
{
    double x = 42.0;
    for ( unsigned long i = 0; i < 10000000; ++i )
        x = std::sin( x );
}

int main()
{
    foo();

    return 0;
}

我使用以下命令。

g++ main.cpp
perf record ./a.out
perf report

我明白了。

Samples: 518  of event 'cycles', Event count (approx.): 410229343
Overhead  Command  Shared Object      Symbol
  84,28%  a.out    libm.so.6          [.] __subtf3
  12,59%  a.out    a.out              [.] foo
   2,47%  a.out    a.out              [.] _init
   0,47%  a.out    [kernel.kallsyms]  [k] may_open
   0,17%  a.out    [kernel.kallsyms]  [k] memcg_slab_post_alloc_hook
   0,01%  perf-ex  [kernel.kallsyms]  [k] mutex_unlock
   0,01%  a.out    [kernel.kallsyms]  [k] __intel_pmu_enable_all.constprop.0
   0,00%  perf-ex  [kernel.kallsyms]  [k] native_write_msr
   0,00%  a.out    [kernel.kallsyms]  [k] native_write_msr

如何理解 foo 的 12.59%?

如何告诉perf report 显示在函数中花费的完整时间百分比?我想看到类似的东西 - foo 99%,__subtf3 90%。

【问题讨论】:

    标签: c++ perf


    【解决方案1】:

    这是答案的一半。关于第二个问题,我会自己回答。

    使用以下命令可以根据需要查看百分比。

    perf record -e cpu-cycles --call-graph dwarf,4096 -F 250 ./a.out
    perf report
    

    结果看起来像。

    +  100,00%     0,00%  a.out    a.out              [.] _start
    +  100,00%     0,00%  a.out    libc.so.6          [.] __libc_start_main_impl (inlined)
    +  100,00%     0,00%  a.out    libc.so.6          [.] __libc_start_call_main (inlined)
    +  100,00%     0,00%  a.out    a.out              [.] main
    +  100,00%    16,27%  a.out    a.out              [.] foo
    +   83,73%     0,00%  a.out    libm.so.6          [.] __sin_fma (inlined)
    +   83,73%    83,73%  a.out    libm.so.6          [.] __subtf3
    +   62,87%     0,00%  a.out    libm.so.6          [.] do_sin (inlined)
    +    5,85%     0,00%  a.out    libm.so.6          [.] libc_feholdsetround_sse_ctx (inlined)                  
    ...
    

    【讨论】:

      猜你喜欢
      • 2022-09-27
      • 2017-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多