我一直在尝试使用perf来分析我正在运行的进程,但我无法理解perf输出的一些数字,下面是我使用的命令和我得到的输出:
$ sudo perf stat -x, -v -e branch-misses,cpu-cycles,cache-misses sleep 1
Using CPUID GenuineIntel-6-55-4
branch-misses: 7751 444665 444665
cpu-cycles: 1212296 444665 444665
cache-misses: 4902 444665 444665
7751,,branch-misses,444665,100.00,,
1212296,,cpu-cycles,444665,100.00,,
4902,,cache-misses,444665,100.00,,我想知道"444665“这个数字代表什么事件?
发布于 2020-07-25 00:10:30
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.因此,您有计数器的值,计数器的空单位,事件名称,运行时间,计数器处于活动状态的百分比(与程序运行时间相比)。
通过比较这两个命令的输出(由comment中的Peter Cordes推荐)
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启动代码和调用syscall nanosleep 1秒(检查strace sleep 1)。因此,在您的输出中,444665是以ns为单位的,或者仅仅是444微秒、0.444毫秒或0.000444秒的libc启动,用于睡眠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 1https://stackoverflow.com/questions/63065486
复制相似问题