如何从性能统计信息的输出中解析指令数和经过的时间



TL;DR

有没有办法使perf stat提供-x时的输出时间经过?

背景

我执行了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可能与我的需求有关,但我无法弄清楚究竟如何。

如果

(config->ru_display)为真print_footer则从tools/perf/util/stat-display.c文件的功能打印"时间已过"。

但是当有设置csv_output的"-x ,"选项时,print_footer不会从perf_evlist__print_counters调用。

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

"用户"/"系统"时间以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 模式下从性能统计信息输出时间。

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

最新更新