监控 Linux 个 cgroup 性能事件
Monitoring Linux performance events for cgroups
我目前正在尝试监视我的系统(6 个硬件计数器和 24 个 CPU)及其 cgroup 的一些硬件事件。我在这里以 LLC 负载和 cpu-周期事件为例。
为此我使用了perf
命令。
但是,当考虑一个空闲的 cgroup(实际上只对应一个 docker 容器 运行 bash)和 运行 perf
对于 cgroup 或系统范围的监控,在这两种情况下,我得到的 cpu 周期数似乎大致相同:
$ sudo perf stat -e LLC-loads,cpu-cycles -a sleep 60
$ sudo perf stat -e instructions,cpu-cycles --cgroup=docker/b1cd988201789e55128393cff5ffbf37b0d6efec0fc70e1b716163b4b1f91f1f -a sleep 60
我原以为我的 cgroup 的 cpu 周期会少很多。 (提供 --cpu=0-23
或 -a
选项时获得相同的结果。)
我是不是漏掉了什么?
我想知道 --cgroup
选项是如何工作的。到底是不是只针对某些事件配置的?
提前感谢您的宝贵时间!
好的,我在文档中找到了答案,但不清楚:
-G name, --cgroup name monitor only in the container (cgroup) called "name". This option is available only in per-cpu mode. The cgroup
filesystem must be mounted. All threads belonging to container "name"
are monitored when they run on the monitored CPUs. Multiple cgroups
can be provided. Each cgroup is applied to the corresponding event,
i.e., first cgroup to first event, second cgroup to second event and
so on. It is possible to provide an empty cgroup (monitor all the
time) using, e.g., -G foo,,bar. Cgroups must have corresponding
events, i.e., they always refer to events defined earlier on the
command line.
这实际上意味着为了在同一个 perf 命令中从 1 个 cgroup 中获取多个事件,我应该列出该 cgroup 的名称与事件数量一样多的次数。
编辑示例(必须使用长容器 ID,但这里为了清楚起见我使用短 ID):
sudo perf stat -e instructions,cpu-cycles,LLC-loads --cgroup=docker/b1cd,docker/b1cd,docker/b1cd -a sleep 60
我目前正在尝试监视我的系统(6 个硬件计数器和 24 个 CPU)及其 cgroup 的一些硬件事件。我在这里以 LLC 负载和 cpu-周期事件为例。
为此我使用了perf
命令。
但是,当考虑一个空闲的 cgroup(实际上只对应一个 docker 容器 运行 bash)和 运行 perf
对于 cgroup 或系统范围的监控,在这两种情况下,我得到的 cpu 周期数似乎大致相同:
$ sudo perf stat -e LLC-loads,cpu-cycles -a sleep 60
$ sudo perf stat -e instructions,cpu-cycles --cgroup=docker/b1cd988201789e55128393cff5ffbf37b0d6efec0fc70e1b716163b4b1f91f1f -a sleep 60
我原以为我的 cgroup 的 cpu 周期会少很多。 (提供 --cpu=0-23
或 -a
选项时获得相同的结果。)
我是不是漏掉了什么?
我想知道 --cgroup
选项是如何工作的。到底是不是只针对某些事件配置的?
提前感谢您的宝贵时间!
好的,我在文档中找到了答案,但不清楚:
-G name, --cgroup name monitor only in the container (cgroup) called "name". This option is available only in per-cpu mode. The cgroup filesystem must be mounted. All threads belonging to container "name" are monitored when they run on the monitored CPUs. Multiple cgroups can be provided. Each cgroup is applied to the corresponding event, i.e., first cgroup to first event, second cgroup to second event and so on. It is possible to provide an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have corresponding events, i.e., they always refer to events defined earlier on the command line.
这实际上意味着为了在同一个 perf 命令中从 1 个 cgroup 中获取多个事件,我应该列出该 cgroup 的名称与事件数量一样多的次数。
编辑示例(必须使用长容器 ID,但这里为了清楚起见我使用短 ID):
sudo perf stat -e instructions,cpu-cycles,LLC-loads --cgroup=docker/b1cd,docker/b1cd,docker/b1cd -a sleep 60