[PATCH] perf annotate: Process synthetic events for pipe mode

From: Namhyung Kim
Date: Fri Feb 01 2013 - 02:51:45 EST


Stephane reported that perf annotate in pipe mode is broken with NULL
evlist. It's because we didn't process ATTR and EVENT_TYPE events in
annoate. Since in pipe mode we cannot get the event info from the
header, it should be handled prior to processing sample events so that
the event and/or evlist are added to the session properly.

I'm not sure TRACING_DATA and BUILD_ID events should also be processed
but adding them will cause no harm I guess. :)

After adding needed callbacks, I realized symbol_conf.nr_events value
should be increased when processing new events/attrs otherwise it'd
get a zero division exception when calling symbol__alloc_hist().

Reported-by: Stephane Eranian <eranian@xxxxxxxxxx>
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/builtin-annotate.c | 4 ++++
tools/perf/util/header.c | 1 +
2 files changed, 5 insertions(+)

diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index dc870cf31b79..5509cc37a829 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -254,6 +254,10 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
.comm = perf_event__process_comm,
.exit = perf_event__process_exit,
.fork = perf_event__process_fork,
+ .attr = perf_event__process_attr,
+ .event_type = perf_event__process_event_type,
+ .tracing_data = perf_event__process_tracing_data,
+ .build_id = perf_event__process_build_id,
.ordered_samples = true,
.ordering_requires_timestamps = true,
},
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 8022b5254f75..274ecd401d41 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2950,6 +2950,7 @@ int perf_event__process_attr(union perf_event *event,
return -ENOMEM;

perf_evlist__add(evlist, evsel);
+ symbol_conf.nr_events++;

ids = event->header.size;
ids -= (void *)&event->attr.id - (void *)event;
--
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/