aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/event.c
diff options
context:
space:
mode:
authorHari Bathini <hbathini@linux.vnet.ibm.com>2017-03-07 15:41:43 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-03-14 10:38:23 -0400
commitf3b3614a284deb124018155a618a7b19694c8b5c (patch)
tree0901f0e0749fa5e2cb0f22ef5239ed62617f9fdc /tools/perf/util/event.c
parente422267322cd319e2695a535e47c5b1feeac45eb (diff)
perf tools: Add PERF_RECORD_NAMESPACES to include namespaces related info
Introduce a new option to record PERF_RECORD_NAMESPACES events emitted by the kernel when fork, clone, setns or unshare are invoked. And update perf-record documentation with the new option to record namespace events. Committer notes: Combined it with a later patch to allow printing it via 'perf report -D' and be able to test the feature introduced in this patch. Had to move here also perf_ns__name(), that was introduced in another later patch. Also used PRIu64 and PRIx64 to fix the build in some enfironments wrt: util/event.c:1129:39: error: format '%lx' expects argument of type 'long unsigned int', but argument 6 has type 'long long unsigned int' [-Werror=format=] ret += fprintf(fp, "%u/%s: %lu/0x%lx%s", idx ^ Testing it: # perf record --namespaces -a ^C[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 1.083 MB perf.data (423 samples) ] # # perf report -D <SNIP> 3 2028902078892 0x115140 [0xa0]: PERF_RECORD_NAMESPACES 14783/14783 - 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] 0x1151e0 [0x30]: event: 9 . . ... raw event: size 48 bytes . 0000: 09 00 00 00 02 00 30 00 c4 71 82 68 0c 7f 00 00 ......0..q.h.... . 0010: a9 39 00 00 a9 39 00 00 94 28 fe 63 d8 01 00 00 .9...9...(.c.... . 0020: 03 00 00 00 00 00 00 00 ce c4 02 00 00 00 00 00 ................ <SNIP> NAMESPACES events: 1 <SNIP> # Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> 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/148891930386.25309.18412039920746995488.stgit@hbathini.in.ibm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/event.c')
-rw-r--r--tools/perf/util/event.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 4ea7ce72ed9c..fb52819023c7 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -31,6 +31,7 @@ static const char *perf_event__names[] = {
31 [PERF_RECORD_LOST_SAMPLES] = "LOST_SAMPLES", 31 [PERF_RECORD_LOST_SAMPLES] = "LOST_SAMPLES",
32 [PERF_RECORD_SWITCH] = "SWITCH", 32 [PERF_RECORD_SWITCH] = "SWITCH",
33 [PERF_RECORD_SWITCH_CPU_WIDE] = "SWITCH_CPU_WIDE", 33 [PERF_RECORD_SWITCH_CPU_WIDE] = "SWITCH_CPU_WIDE",
34 [PERF_RECORD_NAMESPACES] = "NAMESPACES",
34 [PERF_RECORD_HEADER_ATTR] = "ATTR", 35 [PERF_RECORD_HEADER_ATTR] = "ATTR",
35 [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE", 36 [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE",
36 [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA", 37 [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA",
@@ -49,6 +50,16 @@ static const char *perf_event__names[] = {
49 [PERF_RECORD_TIME_CONV] = "TIME_CONV", 50 [PERF_RECORD_TIME_CONV] = "TIME_CONV",
50}; 51};
51 52
53static const char *perf_ns__names[] = {
54 [NET_NS_INDEX] = "net",
55 [UTS_NS_INDEX] = "uts",
56 [IPC_NS_INDEX] = "ipc",
57 [PID_NS_INDEX] = "pid",
58 [USER_NS_INDEX] = "user",
59 [MNT_NS_INDEX] = "mnt",
60 [CGROUP_NS_INDEX] = "cgroup",
61};
62
52const char *perf_event__name(unsigned int id) 63const char *perf_event__name(unsigned int id)
53{ 64{
54 if (id >= ARRAY_SIZE(perf_event__names)) 65 if (id >= ARRAY_SIZE(perf_event__names))
@@ -58,6 +69,13 @@ const char *perf_event__name(unsigned int id)
58 return perf_event__names[id]; 69 return perf_event__names[id];
59} 70}
60 71
72static const char *perf_ns__name(unsigned int id)
73{
74 if (id >= ARRAY_SIZE(perf_ns__names))
75 return "UNKNOWN";
76 return perf_ns__names[id];
77}
78
61static int perf_tool__process_synth_event(struct perf_tool *tool, 79static int perf_tool__process_synth_event(struct perf_tool *tool,
62 union perf_event *event, 80 union perf_event *event,
63 struct machine *machine, 81 struct machine *machine,
@@ -1008,6 +1026,33 @@ size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp)
1008 return fprintf(fp, "%s: %s:%d/%d\n", s, event->comm.comm, event->comm.pid, event->comm.tid); 1026 return fprintf(fp, "%s: %s:%d/%d\n", s, event->comm.comm, event->comm.pid, event->comm.tid);
1009} 1027}
1010 1028
1029size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp)
1030{
1031 size_t ret = 0;
1032 struct perf_ns_link_info *ns_link_info;
1033 u32 nr_namespaces, idx;
1034
1035 ns_link_info = event->namespaces.link_info;
1036 nr_namespaces = event->namespaces.nr_namespaces;
1037
1038 ret += fprintf(fp, " %d/%d - nr_namespaces: %u\n\t\t[",
1039 event->namespaces.pid,
1040 event->namespaces.tid,
1041 nr_namespaces);
1042
1043 for (idx = 0; idx < nr_namespaces; idx++) {
1044 if (idx && (idx % 4 == 0))
1045 ret += fprintf(fp, "\n\t\t ");
1046
1047 ret += fprintf(fp, "%u/%s: %" PRIu64 "/%#" PRIx64 "%s", idx,
1048 perf_ns__name(idx), (u64)ns_link_info[idx].dev,
1049 (u64)ns_link_info[idx].ino,
1050 ((idx + 1) != nr_namespaces) ? ", " : "]\n");
1051 }
1052
1053 return ret;
1054}
1055
1011int perf_event__process_comm(struct perf_tool *tool __maybe_unused, 1056int perf_event__process_comm(struct perf_tool *tool __maybe_unused,
1012 union perf_event *event, 1057 union perf_event *event,
1013 struct perf_sample *sample, 1058 struct perf_sample *sample,
@@ -1016,6 +1061,14 @@ int perf_event__process_comm(struct perf_tool *tool __maybe_unused,
1016 return machine__process_comm_event(machine, event, sample); 1061 return machine__process_comm_event(machine, event, sample);
1017} 1062}
1018 1063
1064int perf_event__process_namespaces(struct perf_tool *tool __maybe_unused,
1065 union perf_event *event,
1066 struct perf_sample *sample,
1067 struct machine *machine)
1068{
1069 return machine__process_namespaces_event(machine, event, sample);
1070}
1071
1019int perf_event__process_lost(struct perf_tool *tool __maybe_unused, 1072int perf_event__process_lost(struct perf_tool *tool __maybe_unused,
1020 union perf_event *event, 1073 union perf_event *event,
1021 struct perf_sample *sample, 1074 struct perf_sample *sample,
@@ -1196,6 +1249,9 @@ size_t perf_event__fprintf(union perf_event *event, FILE *fp)
1196 case PERF_RECORD_MMAP: 1249 case PERF_RECORD_MMAP:
1197 ret += perf_event__fprintf_mmap(event, fp); 1250 ret += perf_event__fprintf_mmap(event, fp);
1198 break; 1251 break;
1252 case PERF_RECORD_NAMESPACES:
1253 ret += perf_event__fprintf_namespaces(event, fp);
1254 break;
1199 case PERF_RECORD_MMAP2: 1255 case PERF_RECORD_MMAP2:
1200 ret += perf_event__fprintf_mmap2(event, fp); 1256 ret += perf_event__fprintf_mmap2(event, fp);
1201 break; 1257 break;