aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2018-01-07 11:03:53 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-01-10 10:00:39 -0500
commit3d7c27b6dbca4c90e7d921b45c2240e7c3cb92a2 (patch)
treeecb6ee74ee84e5fa1e720f1994f6fc223014c345
parent28a0b39877f5ed64ae9fadf95dddb90999309dee (diff)
perf script: Add support to display lost events
Adding option to display lost events: $ perf script --show-lost-events ... mplayer 13810 [002] 468011.402396: 100 cycles:ppp: ff.. mplayer 13810 [002] 468011.402396: PERF_RECORD_LOST lost 3880 mplayer 13810 [002] 468011.402397: 100 cycles:ppp: ff.. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20180107160356.28203-10-jolsa@kernel.org [ Use PRIu64 when printing u64 values, fixing the build in some arches ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/Documentation/perf-script.txt3
-rw-r--r--tools/perf/builtin-script.c28
-rw-r--r--tools/perf/util/event.c8
3 files changed, 39 insertions, 0 deletions
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 93ae8d60e3d3..806ec6391fd6 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -300,6 +300,9 @@ OPTIONS
300 Display context switch events i.e. events of type PERF_RECORD_SWITCH or 300 Display context switch events i.e. events of type PERF_RECORD_SWITCH or
301 PERF_RECORD_SWITCH_CPU_WIDE. 301 PERF_RECORD_SWITCH_CPU_WIDE.
302 302
303--show-lost-events
304 Display lost events i.e. events of type PERF_RECORD_LOST.
305
303--demangle:: 306--demangle::
304 Demangle symbol names to human readable form. It's enabled by default, 307 Demangle symbol names to human readable form. It's enabled by default,
305 disable with --no-demangle. 308 disable with --no-demangle.
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index bb603495cf4a..c1cce474c0f1 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1489,6 +1489,7 @@ struct perf_script {
1489 bool show_mmap_events; 1489 bool show_mmap_events;
1490 bool show_switch_events; 1490 bool show_switch_events;
1491 bool show_namespace_events; 1491 bool show_namespace_events;
1492 bool show_lost_events;
1492 bool allocated; 1493 bool allocated;
1493 bool per_event_dump; 1494 bool per_event_dump;
1494 struct cpu_map *cpus; 1495 struct cpu_map *cpus;
@@ -2080,6 +2081,29 @@ static int process_switch_event(struct perf_tool *tool,
2080 return 0; 2081 return 0;
2081} 2082}
2082 2083
2084static int
2085process_lost_event(struct perf_tool *tool,
2086 union perf_event *event,
2087 struct perf_sample *sample,
2088 struct machine *machine)
2089{
2090 struct perf_script *script = container_of(tool, struct perf_script, tool);
2091 struct perf_session *session = script->session;
2092 struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);
2093 struct thread *thread;
2094
2095 thread = machine__findnew_thread(machine, sample->pid,
2096 sample->tid);
2097 if (thread == NULL)
2098 return -1;
2099
2100 perf_sample__fprintf_start(sample, thread, evsel,
2101 PERF_RECORD_LOST, stdout);
2102 perf_event__fprintf(event, stdout);
2103 thread__put(thread);
2104 return 0;
2105}
2106
2083static void sig_handler(int sig __maybe_unused) 2107static void sig_handler(int sig __maybe_unused)
2084{ 2108{
2085 session_done = 1; 2109 session_done = 1;
@@ -2174,6 +2198,8 @@ static int __cmd_script(struct perf_script *script)
2174 script->tool.context_switch = process_switch_event; 2198 script->tool.context_switch = process_switch_event;
2175 if (script->show_namespace_events) 2199 if (script->show_namespace_events)
2176 script->tool.namespaces = process_namespaces_event; 2200 script->tool.namespaces = process_namespaces_event;
2201 if (script->show_lost_events)
2202 script->tool.lost = process_lost_event;
2177 2203
2178 if (perf_script__setup_per_event_dump(script)) { 2204 if (perf_script__setup_per_event_dump(script)) {
2179 pr_err("Couldn't create the per event dump files\n"); 2205 pr_err("Couldn't create the per event dump files\n");
@@ -3110,6 +3136,8 @@ int cmd_script(int argc, const char **argv)
3110 "Show context switch events (if recorded)"), 3136 "Show context switch events (if recorded)"),
3111 OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events, 3137 OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events,
3112 "Show namespace events (if recorded)"), 3138 "Show namespace events (if recorded)"),
3139 OPT_BOOLEAN('\0', "show-lost-events", &script.show_lost_events,
3140 "Show lost events (if recorded)"),
3113 OPT_BOOLEAN('\0', "per-event-dump", &script.per_event_dump, 3141 OPT_BOOLEAN('\0', "per-event-dump", &script.per_event_dump,
3114 "Dump trace output to files named by the monitored events"), 3142 "Dump trace output to files named by the monitored events"),
3115 OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"), 3143 OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 97a8ef9980db..44e603c27944 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1435,6 +1435,11 @@ size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp)
1435 event->context_switch.next_prev_tid); 1435 event->context_switch.next_prev_tid);
1436} 1436}
1437 1437
1438static size_t perf_event__fprintf_lost(union perf_event *event, FILE *fp)
1439{
1440 return fprintf(fp, " lost %" PRIu64 "\n", event->lost.lost);
1441}
1442
1438size_t perf_event__fprintf(union perf_event *event, FILE *fp) 1443size_t perf_event__fprintf(union perf_event *event, FILE *fp)
1439{ 1444{
1440 size_t ret = fprintf(fp, "PERF_RECORD_%s", 1445 size_t ret = fprintf(fp, "PERF_RECORD_%s",
@@ -1467,6 +1472,9 @@ size_t perf_event__fprintf(union perf_event *event, FILE *fp)
1467 case PERF_RECORD_SWITCH_CPU_WIDE: 1472 case PERF_RECORD_SWITCH_CPU_WIDE:
1468 ret += perf_event__fprintf_switch(event, fp); 1473 ret += perf_event__fprintf_switch(event, fp);
1469 break; 1474 break;
1475 case PERF_RECORD_LOST:
1476 ret += perf_event__fprintf_lost(event, fp);
1477 break;
1470 default: 1478 default:
1471 ret += fprintf(fp, "\n"); 1479 ret += fprintf(fp, "\n");
1472 } 1480 }