[PATCH 2/2] perf header: Prepare tracepoint events regardless of name

Namhyung Kim
2012-09-06T02:18:18Z

From: Namhyung Kim <namhyung.kim@lge.com>

Current perf_evlist__set_tracepoint_names is a misnomer because it
finds and sets correspoding event_format in addition to the name. So
skipping it when a event has set name already caused a trouble.

Rename it and set name only a event doesn't have one.

Reported-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
Arnaldo, I made it incremental for your convenience. But if you want
to drop my previous one I can resend with it. Please let me know your
preference. :)

tools/perf/util/header.c | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index eb7a8da2f4f5..19be34145a18 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2500,33 +2500,39 @@ static int read_attr(int fd, struct perf_header *ph,
return ret <= 0 ? -1 : 0;
}

-static int perf_evsel__set_tracepoint_name(struct perf_evsel *evsel,
- struct pevent *pevent)
+static int perf_evsel__prepare_tracepoint_event(struct perf_evsel *evsel,
+ struct pevent *pevent)
{
- struct event_format *event = pevent_find_event(pevent,
- evsel->attr.config);
+ struct event_format *event;
char bf[128];

+ /* already prepared */
+ if (evsel->tp_format)
+ return 0;
+
+ event = pevent_find_event(pevent, evsel->attr.config);
if (event == NULL)
return -1;

- snprintf(bf, sizeof(bf), "%s:%s", event->system, event->name);
- evsel->name = strdup(bf);
- if (evsel->name == NULL)
- return -1;
+ if (!evsel->name) {
+ snprintf(bf, sizeof(bf), "%s:%s", event->system, event->name);
+ evsel->name = strdup(bf);
+ if (evsel->name == NULL)
+ return -1;
+ }

evsel->tp_format = event;
return 0;
}

-static int perf_evlist__set_tracepoint_names(struct perf_evlist *evlist,
- struct pevent *pevent)
+static int perf_evlist__prepare_tracepoint_events(struct perf_evlist *evlist,
+ struct pevent *pevent)
{
struct perf_evsel *pos;

list_for_each_entry(pos, &evlist->entries, node) {
- if (pos->attr.type == PERF_TYPE_TRACEPOINT && !pos->name &&
- perf_evsel__set_tracepoint_name(pos, pevent))
+ if (pos->attr.type == PERF_TYPE_TRACEPOINT &&
+ perf_evsel__prepare_tracepoint_event(pos, pevent))
return -1;
}

@@ -2614,7 +2620,8 @@ int perf_session__read_header(struct perf_session *session, int fd)

lseek(fd, header->data_offset, SEEK_SET);

- if (perf_evlist__set_tracepoint_names(session->evlist, session->pevent))
+ if (perf_evlist__prepare_tracepoint_events(session->evlist,
+ session->pevent))
goto out_delete_evlist;

header->frozen = 1;
@@ -2848,7 +2855,8 @@ int perf_event__process_tracing_data(union perf_event *event,
if (size_read + padding != size)
die("tracing data size mismatch");

- perf_evlist__set_tracepoint_names(session->evlist, session->pevent);
+ perf_evlist__prepare_tracepoint_events(session->evlist,
+ session->pevent);

return size_read + padding;
}
--
1.7.11.4