1

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!

Lili_marston
  • 149
  • 1
  • 12

1 Answers1

3

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
Lili_marston
  • 149
  • 1
  • 12
  • Can you show example of perf command with correct usage for cgroup (add it to the answer or as comment)? – osgx Nov 27 '17 at 17:56
  • You may want to hightlight the 1:1 mapping relationship of event in event list and cgroup in the cgroup list :-) – ptan May 24 '18 at 09:07
  • Is it possible to automatically terminate the `perf stat` after the container is stopped/removed/killed? I'd like to gather statistics about my container, but the runtime can be anything bettween 1 minute and 2 hours, so I cannot use the sleep command. Thanks! – Alex Jun 29 '18 at 13:44
  • I would run a script killing the perf command with the corresponding container ID, as soon as the container is stopped. But this is off topic. – Lili_marston Jul 02 '18 at 11:13