diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2010-12-07 07:48:42 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-12-09 08:15:07 -0500 |
commit | 3835bc00c5b2d8e337a6e9d7b44f47e02760dba3 (patch) | |
tree | c93ec68b81e3c44c0d6e42d9e2bdeebf38657205 /tools/perf/util | |
parent | b226a5a72901bc9c73d639ea2e53e6c304bf3b74 (diff) |
perf event: Prevent unbound event__name array access
event__name[] is missing an entry for PERF_RECORD_FINISHED_ROUND, but we
happily access the array from the dump code.
Make event__name[] static and provide an accessor function, fix up all
callers and add the missing string.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ian Munsie <imunsie@au1.ibm.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <20101207124550.432593943@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/event.c | 12 | ||||
-rw-r--r-- | tools/perf/util/event.h | 2 | ||||
-rw-r--r-- | tools/perf/util/hist.c | 9 | ||||
-rw-r--r-- | tools/perf/util/session.c | 2 |
4 files changed, 19 insertions, 6 deletions
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index e4cdc1ebe0fb..183aedd4db83 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c | |||
@@ -7,7 +7,7 @@ | |||
7 | #include "strlist.h" | 7 | #include "strlist.h" |
8 | #include "thread.h" | 8 | #include "thread.h" |
9 | 9 | ||
10 | const char *event__name[] = { | 10 | static const char *event__name[] = { |
11 | [0] = "TOTAL", | 11 | [0] = "TOTAL", |
12 | [PERF_RECORD_MMAP] = "MMAP", | 12 | [PERF_RECORD_MMAP] = "MMAP", |
13 | [PERF_RECORD_LOST] = "LOST", | 13 | [PERF_RECORD_LOST] = "LOST", |
@@ -22,8 +22,18 @@ const char *event__name[] = { | |||
22 | [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE", | 22 | [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE", |
23 | [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA", | 23 | [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA", |
24 | [PERF_RECORD_HEADER_BUILD_ID] = "BUILD_ID", | 24 | [PERF_RECORD_HEADER_BUILD_ID] = "BUILD_ID", |
25 | [PERF_RECORD_FINISHED_ROUND] = "FINISHED_ROUND", | ||
25 | }; | 26 | }; |
26 | 27 | ||
28 | const char *event__get_event_name(unsigned int id) | ||
29 | { | ||
30 | if (id >= ARRAY_SIZE(event__name)) | ||
31 | return "INVALID"; | ||
32 | if (!event__name[id]) | ||
33 | return "UNKNOWN"; | ||
34 | return event__name[id]; | ||
35 | } | ||
36 | |||
27 | static struct sample_data synth_sample = { | 37 | static struct sample_data synth_sample = { |
28 | .pid = -1, | 38 | .pid = -1, |
29 | .tid = -1, | 39 | .tid = -1, |
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index a95ab18575ce..4716a8f6d3eb 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h | |||
@@ -171,6 +171,6 @@ int event__preprocess_sample(const event_t *self, struct perf_session *session, | |||
171 | int event__parse_sample(const event_t *event, struct perf_session *session, | 171 | int event__parse_sample(const event_t *event, struct perf_session *session, |
172 | struct sample_data *sample); | 172 | struct sample_data *sample); |
173 | 173 | ||
174 | extern const char *event__name[]; | 174 | const char *event__get_event_name(unsigned int id); |
175 | 175 | ||
176 | #endif /* __PERF_RECORD_H */ | 176 | #endif /* __PERF_RECORD_H */ |
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 2022e8740994..a3b84160c42e 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -1168,10 +1168,13 @@ size_t hists__fprintf_nr_events(struct hists *self, FILE *fp) | |||
1168 | size_t ret = 0; | 1168 | size_t ret = 0; |
1169 | 1169 | ||
1170 | for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) { | 1170 | for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) { |
1171 | if (!event__name[i]) | 1171 | const char *name = event__get_event_name(i); |
1172 | |||
1173 | if (!strcmp(name, "UNKNOWN")) | ||
1172 | continue; | 1174 | continue; |
1173 | ret += fprintf(fp, "%10s events: %10d\n", | 1175 | |
1174 | event__name[i], self->stats.nr_events[i]); | 1176 | ret += fprintf(fp, "%16s events: %10d\n", name, |
1177 | self->stats.nr_events[i]); | ||
1175 | } | 1178 | } |
1176 | 1179 | ||
1177 | return ret; | 1180 | return ret; |
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 3074d38897e6..b3b145a8ff7c 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -718,7 +718,7 @@ static int perf_session__process_event(struct perf_session *session, | |||
718 | if (event->header.type < PERF_RECORD_HEADER_MAX) { | 718 | if (event->header.type < PERF_RECORD_HEADER_MAX) { |
719 | dump_printf("%#Lx [%#x]: PERF_RECORD_%s", | 719 | dump_printf("%#Lx [%#x]: PERF_RECORD_%s", |
720 | file_offset, event->header.size, | 720 | file_offset, event->header.size, |
721 | event__name[event->header.type]); | 721 | event__get_event_name(event->header.type)); |
722 | hists__inc_nr_events(&session->hists, event->header.type); | 722 | hists__inc_nr_events(&session->hists, event->header.type); |
723 | } | 723 | } |
724 | 724 | ||