我有一个程序可以解析linux命令perf的输出。它需要使用选项-x (字段分隔符选项。我想使用perf提取elapsed time (而不是task-time或cpu-clock)。但是,当我使用-x选项时,运行时间不会出现在输出中,并且我找不到相应的perf事件。以下是示例输出
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任何帮助我们都将不胜感激
发布于 2015-02-11 02:57:56
# perf stat ls 2>&1 >/dev/null | tail -n 2 | sed 's/ \+//' | sed 's/ /,/'
0.002272536,seconds time elapsed发布于 2019-09-21 06:39:17
从内核5.2-rc1开始,perf stat公开了一个名为duration_time的新事件来解决这个问题。此事件的值恰好等于time elapsed值,但单位是纳秒而不是秒。
https://stackoverflow.com/questions/27257974
复制相似问题