I am currently trying to monitor some hardware events of my system (6 hardware counters and 24 CPUs) as well as its cgroups. I take here the example of the LLC loads and cpu-cycles events.
To this end I use the perf
command.
However, when considering an idle cgroup (actually corresponding to a docker container only running bash) and running perf
for either cgroups or system wide monitoring, it seems that I am getting approximatly the same number of cpu-cycles in both cases:
$ sudo perf stat -e LLC-loads,cpu-cycles -a sleep 60
$ sudo perf stat -e instructions,cpu-cycles --cgroup=docker/b1cd988201789e55128393cff5ffbf37b0d6efec0fc70e1b716163b4b1f91f1f -a sleep 60
I was expecting a way smaller number of cpu cycles for my cgroups. (Same results are obtained when providing either the --cpu=0-23
or the -a
option.)
Am I missing something here?
I am wondering how the --cgroup
option works. In the end, is it only configured for some events?
Thank you in advance for your time!
Ok I found the answer in the documentation, which is not clear :
-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.
And it actually means that in order to get several events from 1 cgroups in the same perf command, I should list the name of that cgroup as many times as the number of events.
EDIT example (long container IDs must be used, but here I use short IDs for clarity):
sudo perf stat -e instructions,cpu-cycles,LLC-loads --cgroup=docker/b1cd,docker/b1cd,docker/b1cd -a sleep 60