我使用“ 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
Run Code Online (Sandbox Code Playgroud)
(1) 我知道71800964是“ r81d0”的计数,但是1269047979and是什么意思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
Run Code Online (Sandbox Code Playgroud)
这是详细选项的输出,如内核的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 }
Run Code Online (Sandbox Code Playgroud)
计数来自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()syscall打开。有相关部分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. ...
Run Code Online (Sandbox Code Playgroud)
perf stat 如果scale为真,则启用所有 TIME 标志-
298 if (scale)
299 attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
300 PERF_FORMAT_TOTAL_TIME_RUNNING;
Run Code Online (Sandbox Code Playgroud)
所以,第一个计数器是原始事件计数;second 与收集此事件的时间成正比, last 与总运行时间成正比。当您要求perf统计无法一次监控的大量事件(硬件通常最多有 5-7 个性能监控器)时,这是必需的。在这种情况下,内核 perf 将为执行的某些部分运行所需事件的子集;并且子集将被更改多次。使用ena和run计数,perf 可以估计在多路复用的情况下事件监控的不准确程度。
Performance counter stats for './a':
71,800,964 r81d0 [100.00%]
26,655,201 r82d0
Run Code Online (Sandbox Code Playgroud)
在您的情况下,两个事件同时映射而无需多路复用;你ena和run柜台很近。并且print_aggr函数打印它们的比率:
1137 val += counter->counts->cpu[cpu].val;
1138 ena += counter->counts->cpu[cpu].ena;
1139 run += counter->counts->cpu[cpu].run;
Run Code Online (Sandbox Code Playgroud)
如果-r N选择重新运行任务 N 次以获取统计信息,则Print_noise 将输出(人:--repeat=<n>重复命令并打印平均值 + stddev (max: 100))
1176 print_noise(counter, 1.0);
Run Code Online (Sandbox Code Playgroud)
还有[100.00%]打印机:
1178 if (run != ena)
1179 fprintf(output, " (%.2f%%)",
1180 100.0 * run / ena);
Run Code Online (Sandbox Code Playgroud)
如果 run 和 ena 时间相等,并且您的 r82d0 事件相等,则不会打印 100%。您的 r81d0 事件的 run 和 ena 略有不同,因此 100% 打印在一行中。
我知道这perf stat -d可能不准确,因为它要求的事件太多;并且不会有 100% 的多路复用,而是 53%。意思是“这个事件只占程序运行时间的 53%,在它的一些随机部分”;如果您的程序有多个独立的计算阶段,那么具有低运行/ena 比率的事件将不太准确。
| 归档时间: |
|
| 查看次数: |
2135 次 |
| 最近记录: |