perf stat 的-x 格式在man page of perf-stat,CSV 格式部分中进行了描述。此手册页的片段没有可选列:
CSV FORMAT top
With -x, perf stat is able to output a not-quite-CSV format output
Commas in the output are not put into "". To make it easy to parse it
is recommended to use a different character like -x \;
The fields are in this order:
· counter value
· unit of the counter value or empty
· event name
· run time of counter
· percentage of measurement time the counter was running
Additional metrics may be printed with all earlier fields being
empty.
因此,您有计数器的值、计数器的空单位、事件名称、运行时间、活动计数器的百分比(与程序运行时间相比)。
通过比较这两个命令的输出(Peter Cordes in comment 推荐)
perf stat awk 'BEGIN{for(i=0;i<10000000;i++){}}'
perf stat -x \; awk 'BEGIN{for(i=0;i<10000000;i++){}}'
我认为这个计数器一直处于活动状态的运行时间是纳秒。当您使用不冲突的事件集运行perf stat,并且有足够的硬件计数器来计算所有需要的事件时,运行时间将几乎是已分析程序在 CPU 上运行的总时间。 (过大事件集的示例:perf stat -x , -e cycles,instructions,branches,branch-misses,cache-misses,cache-references,mem-loads,mem-stores awk 'BEGIN{for(i=0;i<10000000;i++){}}' - 这些事件的运行时间会有所不同,因为它们在程序执行期间被动态多路复用;而sleep 1 太短而无法激活多路复用。)
对于sleep 1,CPU 上的活动代码非常少,它只是 libc 启动代码并调用系统调用 nanosleep 1 秒(检查 strace sleep 1)。因此,在您的输出中,444665 以 ns 为单位,或者只是 444 微秒或 0.444 毫秒或 0.000444 秒的 libc 启动,用于 sleep 1 进程。
如果您想测量一秒钟的整个系统活动,请尝试添加 perf stat 的 -a 选项(分析所有进程),可选择使用 -A 来分隔 cpu 内核的事件(或使用 -I 100 来定期进行打印):
perf stat -a sleep 1
perf stat -Aa sleep 1
perf stat -a -x , sleep 1
perf stat -Aa -x , sleep 1