Skip to content

Commit cb9dd49

Browse files
committed
perf tools: Fix synthesizing tracepoint names from the perf.data headers
We need to use the per event info snapshoted at record time to synthesize the events name, so do it just after reading the perf.data headers, when we already processed the /sys events data, otherwise we'll end up using the local /sys that only by sheer luck will have the same tracepoint ID -> real event association. Example: # uname -a Linux felicio.ghostprotocols.net 3.4.0-rc5+ svenkatr#1 SMP Sat May 19 15:27:11 BRT 2012 x86_64 x86_64 x86_64 GNU/Linux # perf record -e sched:sched_switch usleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.015 MB perf.data (~648 samples) ] # cat /t/events/sched/sched_switch/id 279 # perf evlist -v sched:sched_switch: sample_freq=1, type: 2, config: 279, size: 80, sample_type: 1159, read_format: 7, disabled: 1, inherit: 1, mmap: 1, comm: 1, enable_on_exec: 1, sample_id_all: 1, exclude_guest: 1 # So on the above machine the sched:sched_switch has tracepoint id 279, but on the machine were we'll analyse it it has a different id: $ cat /t/events/sched/sched_switch/id 56 $ perf evlist -i /tmp/perf.data kmem:mm_balancedirty_writeout $ cat /t/events/kmem/mm_balancedirty_writeout/id 279 With this fix: $ perf evlist -i /tmp/perf.data sched:sched_switch Reported-by: Dmitry Antipov <[email protected]> Cc: David Ahern <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent fc3e4d0 commit cb9dd49

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tools/perf/util/header.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,35 @@ static int read_attr(int fd, struct perf_header *ph,
20932093
return ret <= 0 ? -1 : 0;
20942094
}
20952095

2096+
static int perf_evsel__set_tracepoint_name(struct perf_evsel *evsel)
2097+
{
2098+
struct event_format *event = trace_find_event(evsel->attr.config);
2099+
char bf[128];
2100+
2101+
if (event == NULL)
2102+
return -1;
2103+
2104+
snprintf(bf, sizeof(bf), "%s:%s", event->system, event->name);
2105+
evsel->name = strdup(bf);
2106+
if (event->name == NULL)
2107+
return -1;
2108+
2109+
return 0;
2110+
}
2111+
2112+
static int perf_evlist__set_tracepoint_names(struct perf_evlist *evlist)
2113+
{
2114+
struct perf_evsel *pos;
2115+
2116+
list_for_each_entry(pos, &evlist->entries, node) {
2117+
if (pos->attr.type == PERF_TYPE_TRACEPOINT &&
2118+
perf_evsel__set_tracepoint_name(pos))
2119+
return -1;
2120+
}
2121+
2122+
return 0;
2123+
}
2124+
20962125
int perf_session__read_header(struct perf_session *session, int fd)
20972126
{
20982127
struct perf_header *header = &session->header;
@@ -2174,6 +2203,9 @@ int perf_session__read_header(struct perf_session *session, int fd)
21742203

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

2206+
if (perf_evlist__set_tracepoint_names(session->evlist))
2207+
goto out_delete_evlist;
2208+
21772209
header->frozen = 1;
21782210
return 0;
21792211
out_errno:

0 commit comments

Comments
 (0)