diff options
| author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-08-07 08:58:03 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-08-07 22:43:37 -0400 |
| commit | fcf65bf149afa91b875ffde4455967cb63ee0be9 (patch) | |
| tree | 9b6137e60d4142b1aa00f9e20860bdd8374035d3 /tools/perf/util/scripting-engines | |
| parent | 8b6ee4c5d48d93527dcf6e36c51cbb7703d7fffb (diff) | |
perf evsel: Cache associated event_format
We already lookup the associated event_format when reading the perf.data
header, so that we can cache the tracepoint name in evsel->name, so do
it a little further and save the event_format itself, so that we can
avoid relookups in tools that need to access it.
Change the tools to take the most obvious advantage, when they were
using pevent_find_event directly. More work is needed for further
removing the need of a pointer to pevent, such as when asking for event
field values ("common_pid" and the other common fields and per
event_format fields).
This is something that was planned but only got actually done when
Andrey Wagin needed to do this lookup at perf_tool->sample() time, when
we don't have access to pevent (session->pevent) to use with
pevent_find_event().
Cc: Andrey Wagin <avagin@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: http://lkml.kernel.org/n/tip-txkvew2ckko0b594ae8fbnyk@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/scripting-engines')
| -rw-r--r-- | tools/perf/util/scripting-engines/trace-event-perl.c | 13 | ||||
| -rw-r--r-- | tools/perf/util/scripting-engines/trace-event-python.c | 21 |
2 files changed, 17 insertions, 17 deletions
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c index 02dfa19a467f..c26628116593 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c | |||
| @@ -237,16 +237,16 @@ static void define_event_symbols(struct event_format *event, | |||
| 237 | define_event_symbols(event, ev_name, args->next); | 237 | define_event_symbols(event, ev_name, args->next); |
| 238 | } | 238 | } |
| 239 | 239 | ||
| 240 | static inline | 240 | static inline struct event_format *find_cache_event(struct perf_evsel *evsel) |
| 241 | struct event_format *find_cache_event(struct pevent *pevent, int type) | ||
| 242 | { | 241 | { |
| 243 | static char ev_name[256]; | 242 | static char ev_name[256]; |
| 244 | struct event_format *event; | 243 | struct event_format *event; |
| 244 | int type = evsel->attr.config; | ||
| 245 | 245 | ||
| 246 | if (events[type]) | 246 | if (events[type]) |
| 247 | return events[type]; | 247 | return events[type]; |
| 248 | 248 | ||
| 249 | events[type] = event = pevent_find_event(pevent, type); | 249 | events[type] = event = evsel->tp_format; |
| 250 | if (!event) | 250 | if (!event) |
| 251 | return NULL; | 251 | return NULL; |
| 252 | 252 | ||
| @@ -269,7 +269,6 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused, | |||
| 269 | unsigned long long val; | 269 | unsigned long long val; |
| 270 | unsigned long s, ns; | 270 | unsigned long s, ns; |
| 271 | struct event_format *event; | 271 | struct event_format *event; |
| 272 | int type; | ||
| 273 | int pid; | 272 | int pid; |
| 274 | int cpu = sample->cpu; | 273 | int cpu = sample->cpu; |
| 275 | void *data = sample->raw_data; | 274 | void *data = sample->raw_data; |
| @@ -281,11 +280,9 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused, | |||
| 281 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) | 280 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) |
| 282 | return; | 281 | return; |
| 283 | 282 | ||
| 284 | type = trace_parse_common_type(pevent, data); | 283 | event = find_cache_event(evsel); |
| 285 | |||
| 286 | event = find_cache_event(pevent, type); | ||
| 287 | if (!event) | 284 | if (!event) |
| 288 | die("ug! no event found for type %d", type); | 285 | die("ug! no event found for type %d", evsel->attr.config); |
| 289 | 286 | ||
| 290 | pid = trace_parse_common_pid(pevent, data); | 287 | pid = trace_parse_common_pid(pevent, data); |
| 291 | 288 | ||
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index ce4d1b0c3862..8006978d8398 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #include <errno.h> | 27 | #include <errno.h> |
| 28 | 28 | ||
| 29 | #include "../../perf.h" | 29 | #include "../../perf.h" |
| 30 | #include "../evsel.h" | ||
| 30 | #include "../util.h" | 31 | #include "../util.h" |
| 31 | #include "../event.h" | 32 | #include "../event.h" |
| 32 | #include "../thread.h" | 33 | #include "../thread.h" |
| @@ -194,16 +195,21 @@ static void define_event_symbols(struct event_format *event, | |||
| 194 | define_event_symbols(event, ev_name, args->next); | 195 | define_event_symbols(event, ev_name, args->next); |
| 195 | } | 196 | } |
| 196 | 197 | ||
| 197 | static inline | 198 | static inline struct event_format *find_cache_event(struct perf_evsel *evsel) |
| 198 | struct event_format *find_cache_event(struct pevent *pevent, int type) | ||
| 199 | { | 199 | { |
| 200 | static char ev_name[256]; | 200 | static char ev_name[256]; |
| 201 | struct event_format *event; | 201 | struct event_format *event; |
| 202 | int type = evsel->attr.config; | ||
| 202 | 203 | ||
| 204 | /* | ||
| 205 | * XXX: Do we really need to cache this since now we have evsel->tp_format | ||
| 206 | * cached already? Need to re-read this "cache" routine that as well calls | ||
| 207 | * define_event_symbols() :-\ | ||
| 208 | */ | ||
| 203 | if (events[type]) | 209 | if (events[type]) |
| 204 | return events[type]; | 210 | return events[type]; |
| 205 | 211 | ||
| 206 | events[type] = event = pevent_find_event(pevent, type); | 212 | events[type] = event = evsel->tp_format; |
| 207 | if (!event) | 213 | if (!event) |
| 208 | return NULL; | 214 | return NULL; |
| 209 | 215 | ||
| @@ -217,7 +223,7 @@ struct event_format *find_cache_event(struct pevent *pevent, int type) | |||
| 217 | static void python_process_event(union perf_event *perf_event __unused, | 223 | static void python_process_event(union perf_event *perf_event __unused, |
| 218 | struct pevent *pevent, | 224 | struct pevent *pevent, |
| 219 | struct perf_sample *sample, | 225 | struct perf_sample *sample, |
| 220 | struct perf_evsel *evsel __unused, | 226 | struct perf_evsel *evsel, |
| 221 | struct machine *machine __unused, | 227 | struct machine *machine __unused, |
| 222 | struct thread *thread) | 228 | struct thread *thread) |
| 223 | { | 229 | { |
| @@ -228,7 +234,6 @@ static void python_process_event(union perf_event *perf_event __unused, | |||
| 228 | unsigned long s, ns; | 234 | unsigned long s, ns; |
| 229 | struct event_format *event; | 235 | struct event_format *event; |
| 230 | unsigned n = 0; | 236 | unsigned n = 0; |
| 231 | int type; | ||
| 232 | int pid; | 237 | int pid; |
| 233 | int cpu = sample->cpu; | 238 | int cpu = sample->cpu; |
| 234 | void *data = sample->raw_data; | 239 | void *data = sample->raw_data; |
| @@ -239,11 +244,9 @@ static void python_process_event(union perf_event *perf_event __unused, | |||
| 239 | if (!t) | 244 | if (!t) |
| 240 | Py_FatalError("couldn't create Python tuple"); | 245 | Py_FatalError("couldn't create Python tuple"); |
| 241 | 246 | ||
| 242 | type = trace_parse_common_type(pevent, data); | 247 | event = find_cache_event(evsel); |
| 243 | |||
| 244 | event = find_cache_event(pevent, type); | ||
| 245 | if (!event) | 248 | if (!event) |
| 246 | die("ug! no event found for type %d", type); | 249 | die("ug! no event found for type %d", (int)evsel->attr.config); |
| 247 | 250 | ||
| 248 | pid = trace_parse_common_pid(pevent, data); | 251 | pid = trace_parse_common_pid(pevent, data); |
| 249 | 252 | ||
