使用perf,我们可以测量系统范围的计数器:
$ sudo perf stat -e cpu-cycles
^C
Performance counter stats for 'system wide':
4 247 009 923 cpu-cycles
2,183469627 seconds time elapsed在perf_event_open 手册上,我假设它相当于监视任何cpu (cpu == -1)上的任何pid (pid == -1),但这似乎是不可能的:
Arguments
The pid and cpu arguments allow specifying which process and CPU
to monitor:
pid == 0 and cpu == -1
This measures the calling process/thread on any CPU.
pid == 0 and cpu >= 0
This measures the calling process/thread only when running
on the specified CPU.
pid > 0 and cpu == -1
This measures the specified process/thread on any CPU.
pid > 0 and cpu >= 0
This measures the specified process/thread only when
running on the specified CPU.
pid == -1 and cpu >= 0
This measures all processes/threads on the specified CPU.
This requires CAP_PERFMON (since Linux 5.8) or
CAP_SYS_ADMIN capability or a
/proc/sys/kernel/perf_event_paranoid value of less than 1.
pid == -1 and cpu == -1
This setting is invalid and will return an error.这里的解决办法是什么?
发布于 2022-07-20 15:28:26
看起来,这些选项中没有一个是聚合计数的,它们要么依赖于一个核心,要么跨上下文开关虚拟化计数器。
如果您查看系统范围内的perf stat -a所做的事情(例如使用strace -f perf stat),您可以看到它在每个核心事件中调用perf_event_open一次。它必须将跨核事件的计数加起来;系统调用API不会为您做到这一点。
https://stackoverflow.com/questions/73048527
复制相似问题