Skip to content

Commit 160d4af

Browse files
namhyungacmel
authored andcommitted
perf script: Add --show-cgroup-events option
The --show-cgroup-events option is to print CGROUP events in the output like others. Committer testing: [root@seventh ~]# perf record --all-cgroups --namespaces /wb/cgtest [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.039 MB perf.data (487 samples) ] [root@seventh ~]# perf script --show-cgroup-events | grep PERF_RECORD_CGROUP -B2 -A2 swapper 0 0.000000: PERF_RECORD_CGROUP cgroup: 1 / perf 12145 11200.440730: 1 cycles: ffffffffb900d58b __intel_pmu_enable_all.constprop.0+0x3b (/lib/modules/5.6.0-rc6-00008-gfe2413eefd7f/build/vmlinux) perf 12145 11200.440733: 1 cycles: ffffffffb900d58b __intel_pmu_enable_all.constprop.0+0x3b (/lib/modules/5.6.0-rc6-00008-gfe2413eefd7f/build/vmlinux) -- cgtest 12145 11200.440739: 193472 cycles: ffffffffb90f6fbc commit_creds+0x1fc (/lib/modules/5.6.0-rc6-00008-gfe2413eefd7f/build/vmlinux) cgtest 12145 11200.440790: 2691608 cycles: 7fa2cb43019b _dl_sysdep_start+0x7cb (/usr/lib64/ld-2.29.so) cgtest 12145 11200.440962: PERF_RECORD_CGROUP cgroup: 83 /sub cgtest 12147 11200.441054: 1 cycles: ffffffffb900d58b __intel_pmu_enable_all.constprop.0+0x3b (/lib/modules/5.6.0-rc6-00008-gfe2413eefd7f/build/vmlinux) cgtest 12147 11200.441057: 1 cycles: ffffffffb900d58b __intel_pmu_enable_all.constprop.0+0x3b (/lib/modules/5.6.0-rc6-00008-gfe2413eefd7f/build/vmlinux) -- cgtest 12148 11200.441103: 10227 cycles: ffffffffb9a0153d end_repeat_nmi+0x48 (/lib/modules/5.6.0-rc6-00008-gfe2413eefd7f/build/vmlinux) cgtest 12148 11200.441106: 273295 cycles: ffffffffb99ecbc7 copy_page+0x7 (/lib/modules/5.6.0-rc6-00008-gfe2413eefd7f/build/vmlinux) cgtest 12147 11200.441133: PERF_RECORD_CGROUP cgroup: 88 /sub/cgrp1 cgtest 12147 11200.441143: 2788845 cycles: ffffffffb94676c2 security_genfs_sid+0x102 (/lib/modules/5.6.0-rc6-00008-gfe2413eefd7f/build/vmlinux) cgtest 12148 11200.441162: PERF_RECORD_CGROUP cgroup: 93 /sub/cgrp2 cgtest 12148 11200.441182: 2669546 cycles: 401020 _init+0x20 (/wb/cgtest) cgtest 12149 11200.441247: 1 cycles: ffffffffb900d58b __intel_pmu_enable_all.constprop.0+0x3b (/lib/modules/5.6.0-rc6-00008-gfe2413eefd7f/build/vmlinux) [root@seventh ~]# 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] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent f382842 commit 160d4af

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

tools/perf/Documentation/perf-script.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ OPTIONS
319319
--show-bpf-events
320320
Display bpf events i.e. events of type PERF_RECORD_KSYMBOL and PERF_RECORD_BPF_EVENT.
321321

322+
--show-cgroup-events
323+
Display cgroup events i.e. events of type PERF_RECORD_CGROUP.
324+
322325
--demangle::
323326
Demangle symbol names to human readable form. It's enabled by default,
324327
disable with --no-demangle.

tools/perf/builtin-script.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,7 @@ struct perf_script {
16941694
bool show_lost_events;
16951695
bool show_round_events;
16961696
bool show_bpf_events;
1697+
bool show_cgroup_events;
16971698
bool allocated;
16981699
bool per_event_dump;
16991700
struct evswitch evswitch;
@@ -2212,6 +2213,41 @@ static int process_namespaces_event(struct perf_tool *tool,
22122213
return ret;
22132214
}
22142215

2216+
static int process_cgroup_event(struct perf_tool *tool,
2217+
union perf_event *event,
2218+
struct perf_sample *sample,
2219+
struct machine *machine)
2220+
{
2221+
struct thread *thread;
2222+
struct perf_script *script = container_of(tool, struct perf_script, tool);
2223+
struct perf_session *session = script->session;
2224+
struct evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);
2225+
int ret = -1;
2226+
2227+
thread = machine__findnew_thread(machine, sample->pid, sample->tid);
2228+
if (thread == NULL) {
2229+
pr_debug("problem processing CGROUP event, skipping it.\n");
2230+
return -1;
2231+
}
2232+
2233+
if (perf_event__process_cgroup(tool, event, sample, machine) < 0)
2234+
goto out;
2235+
2236+
if (!evsel->core.attr.sample_id_all) {
2237+
sample->cpu = 0;
2238+
sample->time = 0;
2239+
}
2240+
if (!filter_cpu(sample)) {
2241+
perf_sample__fprintf_start(sample, thread, evsel,
2242+
PERF_RECORD_CGROUP, stdout);
2243+
perf_event__fprintf(event, stdout);
2244+
}
2245+
ret = 0;
2246+
out:
2247+
thread__put(thread);
2248+
return ret;
2249+
}
2250+
22152251
static int process_fork_event(struct perf_tool *tool,
22162252
union perf_event *event,
22172253
struct perf_sample *sample,
@@ -2551,6 +2587,8 @@ static int __cmd_script(struct perf_script *script)
25512587
script->tool.context_switch = process_switch_event;
25522588
if (script->show_namespace_events)
25532589
script->tool.namespaces = process_namespaces_event;
2590+
if (script->show_cgroup_events)
2591+
script->tool.cgroup = process_cgroup_event;
25542592
if (script->show_lost_events)
25552593
script->tool.lost = process_lost_event;
25562594
if (script->show_round_events) {
@@ -3476,6 +3514,7 @@ int cmd_script(int argc, const char **argv)
34763514
.mmap2 = perf_event__process_mmap2,
34773515
.comm = perf_event__process_comm,
34783516
.namespaces = perf_event__process_namespaces,
3517+
.cgroup = perf_event__process_cgroup,
34793518
.exit = perf_event__process_exit,
34803519
.fork = perf_event__process_fork,
34813520
.attr = process_attr,
@@ -3577,6 +3616,8 @@ int cmd_script(int argc, const char **argv)
35773616
"Show context switch events (if recorded)"),
35783617
OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events,
35793618
"Show namespace events (if recorded)"),
3619+
OPT_BOOLEAN('\0', "show-cgroup-events", &script.show_cgroup_events,
3620+
"Show cgroup events (if recorded)"),
35803621
OPT_BOOLEAN('\0', "show-lost-events", &script.show_lost_events,
35813622
"Show lost events (if recorded)"),
35823623
OPT_BOOLEAN('\0', "show-round-events", &script.show_round_events,

0 commit comments

Comments
 (0)