Perf Stat与Perf记录

时间:2018-03-11 04:27:02

标签: perf

我对perf recordperf stat在计算页面错误,缓存未命中以及perf list中的任何其他内容等事件时的区别感到困惑。我在“问题1”的答案下面有2个问题,也可能有助于回答“问题2”,但是在没有问题的情况下,我明确地写出了问题。

问题1: 我的理解是perf stat得到计数的“摘要”,但是当与-I选项一起使用时,会以指定的毫秒间隔获得计数。使用此选项是否可以总结间隔内的计数或获得间隔内的平均值,或完全不同的其他内容?我认为它总结了。 https://coderpad.io/MXNFGTJC表示它已汇总,但我想这可能意味着。

问题2: 为什么perf stat -e <event1> -I 1000 sleep 5没有给出相同的计数,好像我总结了以下命令perf record -e <event1> -F 1000 sleep 5每秒的计数?

例如,如果我使用“page-faults”作为event1的事件,我会得到以下每个命令下面列出的输出。 (我假设句号字段是perf record的perf.data文件中事件的计数)

PERF STAT

    perf stat -e page-faults -I 1000 sleep 5
    #           time             counts unit events
         1.000252928                 54      page-faults                                                 
         2.000498389      <not counted>      page-faults                                                 
         3.000569957      <not counted>      page-faults                                                 
         4.000659987      <not counted>      page-faults                                                 
         5.000837864                  2      page-faults

PERF RECORD

    perf record -e page-faults -F 1000 sleep 5
    [ perf record: Woken up 1 times to write data ]
    [ perf record: Captured and wrote 0.016 MB perf.data (6 samples) ]
    perf script -F period
             1
             1
             1
             5
            38
           164

我希望如果我总结perf stat的计数,我会得到perf record的总和。如果我将-c选项与perf record一起使用并给出参数1,我会得到一个近似匹配。由于页面错误的数量相对较少,这只是巧合吗?

到目前为止我使用的参考文献:

  • perf wiki
  • 上面提到的brendangregg's perf blog上的perf记录和统计链接为“perf wiki”
  • 我在this page周围挖掘,看看当记录实际记录的时间和时间,以及写入perf.data的时间。

提前感谢您提供的任何和所有见解。

1 个答案:

答案 0 :(得分:6)

首先,您使用sleeppage-faults的测试用例不是理想的测试用例。在睡眠期间不应该有任何页面错误事件,你真的不能期待任何有趣的事情。为了便于推理,我建议使用ref-cycles(硬件)事件和繁忙的工作负载,例如awk 'BEGIN { while(1){} }'

  

问题1:据我所知,perf stat获得了“摘要”   计数,但与-I选项一起使用时获取计数   指定的毫秒间隔。有了这个选项,它总结了   计算间隔或计算间隔的平均值,或   完全不同的东西?我认为它总结了。

是。这些值只是总结了一下。您可以通过测试确认:

$ perf stat -e ref-cycles -I 1000 timeout 10s awk 'BEGIN { while(1){} }'
#           time             counts unit events
 1.000105072      2,563,666,664      ref-cycles                                                  
 2.000267991      2,577,462,550      ref-cycles                                                  
 3.000415395      2,577,211,936      ref-cycles                                                  
 4.000543311      2,577,240,458      ref-cycles                                                  
 5.000702131      2,577,525,002      ref-cycles                                                  
 6.000857663      2,577,156,088      ref-cycles                                                  

[ ... snip ... ]
[ Note that it may not be as nicely consistent on all systems due dynamic frequency scaling ]

$ perf stat -e ref-cycles -I 3000 timeout 10s awk 'BEGIN { while(1){} }' 
#           time             counts unit events
 3.000107921      7,736,108,718      ref-cycles                                                  
 6.000265186      7,732,065,900      ref-cycles                                                  
 9.000372029      7,728,302,192      ref-cycles     
  

问题2:为什么perf stat -e <event1> -I 1000 sleep 5没有给出   大约相同的计数,好像我总结了每秒的计数   对于以下命令perf record -e <event1> -F 1000 sleep 5

perf stat -I位于毫秒,而perf record -F位于 HZ (1 / s),因此perf stat -I 1000的相应命令是perf record -F 1。事实上,对于我们更稳定的事件/工作负载,这看起来更好:

$ perf stat -e ref-cycles -I 1000 timeout 10s awk 'BEGIN { while(1){} }'
#           time             counts unit events
 1.000089518      2,578,694,534      ref-cycles                                                  
 2.000203872      2,579,866,250      ref-cycles                                                  
 3.000294300      2,579,857,852      ref-cycles                                                  
 4.000390273      2,579,964,842      ref-cycles                                                  
 5.000488375      2,577,955,536      ref-cycles                                                  
 6.000587028      2,577,176,316      ref-cycles                                                  
 7.000688250      2,577,334,786      ref-cycles                                                  
 8.000785388      2,577,581,500      ref-cycles                                                  
 9.000876466      2,577,511,326      ref-cycles                                                  
10.000977965      2,577,344,692      ref-cycles                                                  
10.001195845            466,674      ref-cycles    

$ perf record -e ref-cycles -F 1 timeout 10s awk 'BEGIN { while(1){} }'
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.008 MB perf.data (17 samples) ]

$ perf script -F time,period        
3369070.273722:          1 
3369070.273755:          1 
3369070.273911:       3757 
3369070.273916:    3015133 
3369070.274486:          1 
3369070.274556:          1 
3369070.274657:       1778 
3369070.274662:    2196921 
3369070.275523: 47192985748 
3369072.663696: 2578692405 
3369073.663547: 2579122382 
3369074.663609: 2580015300 
3369075.664085: 2579873741 
3369076.664433: 2578638211 
3369077.664379: 2578378119 
3369078.664175: 2578166440 
3369079.663896: 2579238122 

所以你看,最终perf record -F的结果也是稳定的。不幸的是,perf record的文档很差。通过查看基础系统调用-c的文档,您可以了解设置-Fman perf_event_open的含义:

  

sample_periodsample_freq“抽样”事件就是这样的事件   每N个事件产生一个溢出通知,其中N由下式给出   sample_period。抽样活动有sample_period&gt; 0.什么时候   发生溢出,请求的数据记录在mmap缓冲区中。   sample_type字段控制每个数据的记录数据   溢出。

     如果您希望使用频率而不是使用频率,则可以使用

sample_freq   期。在这种情况下,您可以设置freq标志。 内核会   调整采样周期以尝试达到所需的速率。   调整率是一个计时器滴答。

因此,perf stat使用内部计时器每隔-i毫秒读取计数器的值,perf record设置事件溢出计数器,以便每-c个事件采样一次。这意味着它会在每N个事件中采样一次(例如,每N page-faultcycles。使用-F时,它会尝试调节此溢出值以达到所需的频率。它尝试不同的值并相应地调高/调低它。这最终适用于具有稳定速率的计数器,但会对动态事件产生不稳定的结果。

相关问题