【问题标题】:perf get time elasped with field separator optionperf 使用字段分隔符选项获取时间
【发布时间】:2014-12-02 20:06:55
【问题描述】:

我有一个程序可以解析 linux 命令 perf 的输出。它需要使用选项-x,(字段分隔符选项。我想使用perf提取elapsed time(不是task-timecpu-clock)。但是当我使用-x选项时,经过的时间是输出中不存在,我找不到相应的性能事件。这是示例输出

perf stat ls
============
 Performance counter stats for 'ls':

          0.934889 task-clock (msec)         #    0.740 CPUs utilized          
                 6 context-switches          #    0.006 M/sec                  
                 0 cpu-migrations            #    0.000 K/sec                  
               261 page-faults               #    0.279 M/sec                  
         1,937,910 cycles                    #    2.073 GHz                    
   <not supported> stalled-cycles-frontend 
   <not supported> stalled-cycles-backend  
         1,616,944 instructions              #    0.83  insns per cycle        
           317,016 branches                  #  339.095 M/sec                  
            12,439 branch-misses             #    3.92% of all branches        

       0.001262625 seconds time elapsed //here we have it

现在带有字段分隔符选项

perf stat -x, ls
================
2.359807,task-clock
6,context-switches
0,cpu-migrations
261,page-faults
1863028,cycles
<not supported>,stalled-cycles-frontend
<not supported>,stalled-cycles-backend
1670644,instructions
325047,branches
12251,branch-misses

感谢任何帮助

【问题讨论】:

  • 为什么不改变性能源来打印它。
  • 在查看 perf 源代码后,我发现使用字段分隔符时目前没有任何方法可以打印它。我想知道为什么。我认为如果有人想要在常规报告中使用这些数据,他们可能想要在字段分隔视图中使用它。
  • @Milind 更改 perf 源代码的问题是,当我必须分发我的代码时,我还必须分发自定义 perf。但是,正如 Gabriel 所说,如果当前 perf 代码中没有办法,我会尝试创建一个补丁文件并发送给 perf 维护者
  • 您的程序使用哪种语言解析格式化的输出?除了解析“perf stat ls”的输出之外,我没有其他选择。
  • @Milind 是的,这是可能的。但是我使用的工具不支持正常输出。字段分隔的输出更容易解析。最后,我创建了一个自定义解析器来将正常输出转换为字段分隔输出并使用它。

标签: linux performance perf


【解决方案1】:
# perf stat ls 2>&1 >/dev/null | tail -n 2 | sed 's/ \+//' | sed 's/ /,/'

0.002272536,seconds time elapsed

【讨论】:

    【解决方案2】:

    从内核 5.2-rc1 开始,perf stat 公开了一个名为 duration_time 的新事件,以解决这个问题。此事件的值与time elapsed 值完全相同,但单位是纳秒而不是秒。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-19
      • 1970-01-01
      • 2013-04-21
      • 2014-03-12
      • 2017-12-02
      • 1970-01-01
      相关资源
      最近更新 更多