diff options
author | Hari Bathini <hbathini@linux.vnet.ibm.com> | 2017-03-07 15:42:06 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-03-14 14:17:36 -0400 |
commit | 96a44bbccdd8ff263829d42fe934e6094ea5bb20 (patch) | |
tree | 4226926d027136d23d970c332c2b458307a95b6f /tools/perf/builtin-script.c | |
parent | e907caf3a07ee42ef08ba689a436fd1eb99fbf62 (diff) |
perf script: Add script print support for namespace events
Introduce a new option to display events of type PERF_RECORD_NAMESPACES
and update perf-script documentation accordingly.
Shown below is output (trimmed) of perf script command with the newly
introduced option, on perf.data generated with perf record command using
--namespaces option.
$ perf script --show-namespace-events
swapper 0 [000] 0.000000: PERF_RECORD_NAMESPACES 1/1 - nr_namespaces: 7
[0/net: 3/0xf000001c, 1/uts: 3/0xeffffffe, 2/ipc: 3/0xefffffff, 3/pid: 3/0xeffffffc,
4/user: 3/0xeffffffd, 5/mnt: 3/0xf0000000, 6/cgroup: 3/0xeffffffb]
swapper 0 [000] 0.000000: PERF_RECORD_NAMESPACES 2/2 - nr_namespaces: 7
[0/net: 3/0xf000001c, 1/uts: 3/0xeffffffe, 2/ipc: 3/0xefffffff, 3/pid: 3/0xeffffffc,
4/user: 3/0xeffffffd, 5/mnt: 3/0xf0000000, 6/cgroup: 3/0xeffffffb]
Commiter notes:
Testing it:
Investigating that double PERF_RECORD_NAMESPACES for the 19155
pid/tid... Its more than that, there are two PERF_RECORD_COMM as well,
and with zeroed timestamps, so probably a synthesizing artifact...
# perf script --show-task --show-namespace
<SNIP>
perf 0 [000] 0.000000: PERF_RECORD_COMM: perf:19154/19154
perf 0 [000] 0.000000: PERF_RECORD_FORK(19155:19155):(19154:19154)
perf 0 [000] 0.000000: PERF_RECORD_NAMESPACES 19155/19155 - nr_namespaces: 7
[0/net: 3/0xf0000081, 1/uts: 3/0xeffffffe, 2/ipc: 3/0xefffffff, 3/pid: 3/0xeffffffc,
4/user: 3/0xeffffffd, 5/mnt: 3/0xf0000000, 6/cgroup: 3/0xeffffffb]
perf 0 [000] 0.000000: PERF_RECORD_COMM: perf:19155/19155
perf 0 [000] 0.000000: PERF_RECORD_COMM: perf:19155/19155
perf 0 [000] 0.000000: PERF_RECORD_NAMESPACES 19155/19155 - nr_namespaces: 7
[0/net: 3/0xf0000081, 1/uts: 3/0xeffffffe, 2/ipc: 3/0xefffffff, 3/pid: 3/0xeffffffc,
4/user: 3/0xeffffffd, 5/mnt: 3/0xf0000000, 6/cgroup: 3/0xeffffffb]
swapper 0 [000] 3110.881834: 1 cycles: ffffffffa7060bf6 native_write_msr (/lib/modules/4.11.0-rc1+/build/vmlinux)
<SNIP>
Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Aravinda Prasad <aravinda@linux.vnet.ibm.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sargun Dhillon <sargun@sargun.me>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/148891932627.25309.1941587059154176221.stgit@hbathini.in.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-script.c')
-rw-r--r-- | tools/perf/builtin-script.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index f1ce806a1f31..66d62c98dff9 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -830,6 +830,7 @@ struct perf_script { | |||
830 | bool show_task_events; | 830 | bool show_task_events; |
831 | bool show_mmap_events; | 831 | bool show_mmap_events; |
832 | bool show_switch_events; | 832 | bool show_switch_events; |
833 | bool show_namespace_events; | ||
833 | bool allocated; | 834 | bool allocated; |
834 | struct cpu_map *cpus; | 835 | struct cpu_map *cpus; |
835 | struct thread_map *threads; | 836 | struct thread_map *threads; |
@@ -1118,6 +1119,41 @@ out: | |||
1118 | return ret; | 1119 | return ret; |
1119 | } | 1120 | } |
1120 | 1121 | ||
1122 | static int process_namespaces_event(struct perf_tool *tool, | ||
1123 | union perf_event *event, | ||
1124 | struct perf_sample *sample, | ||
1125 | struct machine *machine) | ||
1126 | { | ||
1127 | struct thread *thread; | ||
1128 | struct perf_script *script = container_of(tool, struct perf_script, tool); | ||
1129 | struct perf_session *session = script->session; | ||
1130 | struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id); | ||
1131 | int ret = -1; | ||
1132 | |||
1133 | thread = machine__findnew_thread(machine, event->namespaces.pid, | ||
1134 | event->namespaces.tid); | ||
1135 | if (thread == NULL) { | ||
1136 | pr_debug("problem processing NAMESPACES event, skipping it.\n"); | ||
1137 | return -1; | ||
1138 | } | ||
1139 | |||
1140 | if (perf_event__process_namespaces(tool, event, sample, machine) < 0) | ||
1141 | goto out; | ||
1142 | |||
1143 | if (!evsel->attr.sample_id_all) { | ||
1144 | sample->cpu = 0; | ||
1145 | sample->time = 0; | ||
1146 | sample->tid = event->namespaces.tid; | ||
1147 | sample->pid = event->namespaces.pid; | ||
1148 | } | ||
1149 | print_sample_start(sample, thread, evsel); | ||
1150 | perf_event__fprintf(event, stdout); | ||
1151 | ret = 0; | ||
1152 | out: | ||
1153 | thread__put(thread); | ||
1154 | return ret; | ||
1155 | } | ||
1156 | |||
1121 | static int process_fork_event(struct perf_tool *tool, | 1157 | static int process_fork_event(struct perf_tool *tool, |
1122 | union perf_event *event, | 1158 | union perf_event *event, |
1123 | struct perf_sample *sample, | 1159 | struct perf_sample *sample, |
@@ -1293,6 +1329,8 @@ static int __cmd_script(struct perf_script *script) | |||
1293 | } | 1329 | } |
1294 | if (script->show_switch_events) | 1330 | if (script->show_switch_events) |
1295 | script->tool.context_switch = process_switch_event; | 1331 | script->tool.context_switch = process_switch_event; |
1332 | if (script->show_namespace_events) | ||
1333 | script->tool.namespaces = process_namespaces_event; | ||
1296 | 1334 | ||
1297 | ret = perf_session__process_events(script->session); | 1335 | ret = perf_session__process_events(script->session); |
1298 | 1336 | ||
@@ -2181,6 +2219,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) | |||
2181 | "Show the mmap events"), | 2219 | "Show the mmap events"), |
2182 | OPT_BOOLEAN('\0', "show-switch-events", &script.show_switch_events, | 2220 | OPT_BOOLEAN('\0', "show-switch-events", &script.show_switch_events, |
2183 | "Show context switch events (if recorded)"), | 2221 | "Show context switch events (if recorded)"), |
2222 | OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events, | ||
2223 | "Show namespace events (if recorded)"), | ||
2184 | OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"), | 2224 | OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"), |
2185 | OPT_BOOLEAN(0, "ns", &nanosecs, | 2225 | OPT_BOOLEAN(0, "ns", &nanosecs, |
2186 | "Use 9 decimal places when displaying time"), | 2226 | "Use 9 decimal places when displaying time"), |