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 counter
、optional metric value
和optional 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_utime
和ru_data.ru_stime
为单位,"经过的秒时间"是config->walltime_nsecs_stats
的平均值。
stat-display.c
中没有其他代码来显示ru_data.ru_utime
、ru_data.ru_stime
或walltime_nsecs_stats
,因此在 Linux 内核版本 4.20 中,不可能在 CSV 模式下从性能统计信息输出时间。
您可以修补stat-display.c
文件以输出所需的任何内容并编译perf
(cd tools/perf; make
)。 来自其他内核版本的 perf 工具将适用于任何 Linux 内核。