首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >系统宽perf_event_open

系统宽perf_event_open
EN

Stack Overflow用户
提问于 2022-07-20 08:47:28
回答 1查看 124关注 0票数 1

使用perf,我们可以测量系统范围的计数器:

代码语言:javascript
复制
$ 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),但这似乎是不可能的:

代码语言:javascript
复制
   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.

这里的解决办法是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-20 15:28:26

看起来,这些选项中没有一个是聚合计数的,它们要么依赖于一个核心,要么跨上下文开关虚拟化计数器。

如果您查看系统范围内的perf stat -a所做的事情(例如使用strace -f perf stat),您可以看到它在每个核心事件中调用perf_event_open一次。它必须将跨核事件的计数加起来;系统调用API不会为您做到这一点。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73048527

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档