performance - "perf stat"输出是什么意思?

标签 performance perf

我使用“perf stat”命令对一些事件进行统计:

[root@root test]# perf stat -a -e "r81d0","r82d0" -v ./a
r81d0: 71800964 1269047979 1269006431
r82d0: 26655201 1284214869 1284214869

 Performance counter stats for './a':

        71,800,964 r81d0                                                        [100.00%]
        26,655,201 r82d0

       0.036892349 seconds time elapsed

(1) 我知道 71800964是“r81d0”的计数,但是1269047979是什么意思和 1269006431 ?
(2) “[100.00%]”是什么意思?

我试过“perf stat --help”,但无法得到这些值的解释。

最佳答案

[root@root test]# perf stat -a -e "r81d0","r82d0" -v ./a
r81d0: 71800964 1269047979 1269006431
r82d0: 26655201 1284214869 1284214869

这是详细选项的输出,如 tools/perf/builtin-stat.c 中所定义内核文件:
391 /*
392  * Read out the results of a single counter:
393  * aggregate counts across CPUs in system-wide mode
394  */
395 static int read_counter_aggr(struct perf_evsel *counter)

408         if (verbose) {
409                 fprintf(output, "%s: %" PRIu64 " %" PRIu64 " %" PRIu64 "\n",
410                         perf_evsel__name(counter), count[0], count[1], count[2]);
411         }

计数来自 struct perf_counts_values ,定义为 http://lxr.free-electrons.com/source/tools/perf/util/evsel.h?v=3.18#L12具有三个 uint64_t 值的数组,命名为 val , ena , run
count值由内核填充并从 fd 读取,以 perf_event_open() 打开系统调用。 man perf_event_open有相关部分:http://man7.org/linux/man-pages/man2/perf_event_open.2.html
   read_format
          This field specifies the format of the data returned by
          read(2) on a perf_event_open() file descriptor.

          PERF_FORMAT_TOTAL_TIME_ENABLED
                 Adds the 64-bit time_enabled field.  This can be used
                 to calculate estimated totals if the PMU is
                 overcommitted and multiplexing is happening.

          PERF_FORMAT_TOTAL_TIME_RUNNING
                 Adds the 64-bit time_running field.  This can be used
                 to calculate estimated totals if the PMU is
                 overcommitted and multiplexing is happening.  ...
perf stat enables all TIME flags如果 scale是真的 -
298         if (scale)
299                 attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
300                                     PERF_FORMAT_TOTAL_TIME_RUNNING;

所以,第一个计数器是原始事件计数; second 与收集此事件的时间成正比, last 与总运行时间成正比。当你问 perf 时需要这个统计大量事件,这些事件不能一次被监控(硬件通常有多达 5-7 个性能监控器)。在这种情况下,内核 perf 将为执行的某些部分运行所需事件的子集;并且子集将被更改多次。与 enarun计数, perf 可以估计在多路复用的情况下事件监控的不准确程度。
 Performance counter stats for './a':

    71,800,964 r81d0                                            [100.00%]
    26,655,201 r82d0

在您的情况下,两个事件同时映射而无需多路复用;您的 enarun柜台很近。和 print_aggr 函数打印它们的比率:
1137                                 val += counter->counts->cpu[cpu].val;
1138                                 ena += counter->counts->cpu[cpu].ena;
1139                                 run += counter->counts->cpu[cpu].run;

如果出现 -r N,将输出 Print_noise重新运行任务 N 次以获取统计信息的选项(人:--repeat=<n> 重复命令并打印平均值 + 标准偏差(最大值:100))
1176                                 print_noise(counter, 1.0);

还有[100.00%]打印机:
1178                                 if (run != ena)
1179                                         fprintf(output, "  (%.2f%%)",
1180                                                 100.0 * run / ena);

如果 run 和 ena 时间相等,并且您的 r82d0 事件相等,则不会打印 100%。您的 r81d0 事件的 run 和 ena 略有不同,因此 100% 打印在一行中。

我知道perf stat -d可能不准确,因为它要求的事件太多;并且不会有 100% 的多路复用,而是大约 53%。意思是“这个事件只占程序运行时间的 53%,在它的一些随机部分”;如果您的程序有多个独立的计算阶段,那么具有低运行/ena 比率的事件将不太准确。

关于performance - "perf stat"输出是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28958392/

相关文章:

c# - 在 XML 文件中查找节点 - C# 中的性能改进

performance - 提高保留每个账户查询最近3条记录的性能

c - read() 系统调用页面错误不依赖于文件大小

linux - 改变 perf_event_mlock_kb 的后果

memory - 为什么较新的 Intel CPU 不支持停止循环后端的性能计数器?

android - 如何在 Android 设备上执行 perf(linux 工具)?

mysql - 如何加快这个缓慢的查询

performance - 用于压力、负载和性能测试的开源工具

.net - .Net 中没有 'payload' 值的字典

performancecounter - Perf:[<n percent>] 记录在 perf stat 输出中是什么意思?