Skip to content

Commit f382842

Browse files
namhyungacmel
authored andcommitted
perf top: Add --all-cgroups option
The --all-cgroups option is to enable cgroup profiling support. It tells kernel to record CGROUP events in the ring buffer so that 'perf top' can identify task/cgroup association later. Committer testing: Use: # perf top --all-cgroups -s cgroup_id,cgroup,pid Signed-off-by: Namhyung Kim <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Link: http://lore.kernel.org/lkml/[email protected] [ Extracted the HAVE_FILE_HANDLE from the followup patch ] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 8fb4b67 commit f382842

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

tools/perf/Documentation/perf-top.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ Default is to monitor all CPUS.
272272
Record events of type PERF_RECORD_NAMESPACES and display it with the
273273
'cgroup_id' sort key.
274274

275+
--all-cgroups::
276+
Record events of type PERF_RECORD_CGROUP and display it with the
277+
'cgroup' sort key.
278+
275279
--switch-on EVENT_NAME::
276280
Only consider events after this event is found.
277281

tools/perf/builtin-top.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,13 +1246,26 @@ static int __cmd_top(struct perf_top *top)
12461246

12471247
if (opts->record_namespaces)
12481248
top->tool.namespace_events = true;
1249+
if (opts->record_cgroup) {
1250+
#ifdef HAVE_FILE_HANDLE
1251+
top->tool.cgroup_events = true;
1252+
#else
1253+
pr_err("cgroup tracking is not supported.\n");
1254+
return -1;
1255+
#endif
1256+
}
12491257

12501258
ret = perf_event__synthesize_bpf_events(top->session, perf_event__process,
12511259
&top->session->machines.host,
12521260
&top->record_opts);
12531261
if (ret < 0)
12541262
pr_debug("Couldn't synthesize BPF events: Pre-existing BPF programs won't have symbols resolved.\n");
12551263

1264+
ret = perf_event__synthesize_cgroups(&top->tool, perf_event__process,
1265+
&top->session->machines.host);
1266+
if (ret < 0)
1267+
pr_debug("Couldn't synthesize cgroup events.\n");
1268+
12561269
machine__synthesize_threads(&top->session->machines.host, &opts->target,
12571270
top->evlist->core.threads, false,
12581271
top->nr_threads_synthesize);
@@ -1545,6 +1558,8 @@ int cmd_top(int argc, const char **argv)
15451558
"number of thread to run event synthesize"),
15461559
OPT_BOOLEAN(0, "namespaces", &opts->record_namespaces,
15471560
"Record namespaces events"),
1561+
OPT_BOOLEAN(0, "all-cgroups", &opts->record_cgroup,
1562+
"Record cgroup events"),
15481563
OPTS_EVSWITCH(&top.evswitch),
15491564
OPT_END()
15501565
};

0 commit comments

Comments
 (0)