【问题标题】:How to parse number of instructions and elapsed time from output of perf stat如何从 perf stat 的输出中解析指令数和经过的时间
【发布时间】:2019-05-30 00:24:18
【问题描述】:

TL;DR

提供-x 时,有什么方法可以使perf stat 输出时间过去?

背景

我执行了perf stat -e instructions:u make run,输出粘贴在下面。

 Performance counter stats for 'make run':

    53,781,961,288      instructions:u

       2.802749955 seconds time elapsed

      21.453244000 seconds user
       0.249223000 seconds sys

我想解析指令数和经过的时间,所以我添加-x选项使输出用逗号分隔,对应的输出粘贴在下面。

53781782267,,instructions:u,20694056846,100.00,,

我注意到没有显示所有时间测量值,因此我检查了perf help stat 的输出。在CSV FORMAT 部分,我发现run time of counteroptional metric valueoptional unit of metric 可能与我的需求有关,但我无法弄清楚究竟是什么。

【问题讨论】:

  • 你的perf和linux内核版本是多少?
  • @osgx 性能:4.19.g84df95,linux 内核:4.17.11-arch1 (by uname -r)

标签: linux profiling perf


【解决方案1】:

如果(config->ru_display) 为真,则从tools/perf/util/stat-display.c fileprint_footer 函数打印“经过的时间”。

但是当存在设置 csv_output 的“-x ,”选项时,print_footer 不会从 perf_evlist__print_counters 调用。

if (!interval && !config->csv_output)
    print_footer(config);

“user”/“sys”时间在 config->ru_data.ru_utimeru_data.ru_stime 中,“经过的秒数”是 config->walltime_nsecs_stats 的平均值。

stat-display.c 中没有其他代码可以显示ru_data.ru_utimeru_data.ru_stimewalltime_nsecs_stats,因此在 Linux 内核版本 4.20 中,无法在 CSV 模式下从 perf stat 输出时间。

您可以修补stat-display.c 文件以输出您需要的任何内容并编译perf (cd tools/perf; make)。其他内核版本的 perf 工具适用于任何 linux 内核。

【讨论】:

  • 您可以尝试使用perf stat /usr/bin/time -f '%e,%U,%s' ./your_program 从 GNU 时间程序中获取运行时间,或者使用来自man time 的不同格式字符串。
  • 感谢您的详细解释。这是否意味着我必须 1. 下载 linux 内核源代码 2. 根据需要修改 <kernel source code dir>/tools/perf/util/stat-display.c 3. 编译它并用原始性能替换它?我也想知道这是否会影响其他用户,因为我正在工作站上工作。对不起,如果这听起来很傻,我正在学习我的第一门关于 linux 的课程并努力熟悉它:)
  • 大卫,你可以试试perf stat /usr/bin/time -f FORMAT_STRING 解决方案。或者是的,您可以下载内核源代码,将目录更改为 tools/perf,编辑文件并运行 make。你不能(或不应该)替换系统性能二进制文件,只需从它所在的位置运行它(或将其复制到您的某个目录,如/home/david/bin/perf)。
  • 我最终确实使用了FORMAT_STRING 解决方案,感谢您提供的所有信息!
猜你喜欢
  • 1970-01-01
  • 2015-05-16
  • 2014-12-06
  • 2021-08-03
  • 1970-01-01
  • 2016-07-18
  • 2013-02-09
  • 2020-04-14
相关资源
最近更新 更多