Skip to content

Commit

Permalink
perf top: Add --all-cgroups option
Browse files Browse the repository at this point in the history
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 <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20200325124536.2800725-9-namhyung@kernel.org
Link: http://lore.kernel.org/lkml/20200402015249.3800462-1-namhyung@kernel.org
[ Extracted the HAVE_FILE_HANDLE from the followup patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Namhyung Kim authored and Arnaldo Carvalho de Melo committed Apr 3, 2020
1 parent 8fb4b67 commit f382842
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/perf/Documentation/perf-top.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ Default is to monitor all CPUS.
Record events of type PERF_RECORD_NAMESPACES and display it with the
'cgroup_id' sort key.

--all-cgroups::
Record events of type PERF_RECORD_CGROUP and display it with the
'cgroup' sort key.

--switch-on EVENT_NAME::
Only consider events after this event is found.

Expand Down
15 changes: 15 additions & 0 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -1246,13 +1246,26 @@ static int __cmd_top(struct perf_top *top)

if (opts->record_namespaces)
top->tool.namespace_events = true;
if (opts->record_cgroup) {
#ifdef HAVE_FILE_HANDLE
top->tool.cgroup_events = true;
#else
pr_err("cgroup tracking is not supported.\n");
return -1;
#endif
}

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

ret = perf_event__synthesize_cgroups(&top->tool, perf_event__process,
&top->session->machines.host);
if (ret < 0)
pr_debug("Couldn't synthesize cgroup events.\n");

machine__synthesize_threads(&top->session->machines.host, &opts->target,
top->evlist->core.threads, false,
top->nr_threads_synthesize);
Expand Down Expand Up @@ -1545,6 +1558,8 @@ int cmd_top(int argc, const char **argv)
"number of thread to run event synthesize"),
OPT_BOOLEAN(0, "namespaces", &opts->record_namespaces,
"Record namespaces events"),
OPT_BOOLEAN(0, "all-cgroups", &opts->record_cgroup,
"Record cgroup events"),
OPTS_EVSWITCH(&top.evswitch),
OPT_END()
};
Expand Down

0 comments on commit f382842

Please sign in to comment.