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/trace-event-python.c | |
| 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/trace-event-python.c')
| -rw-r--r-- | tools/perf/util/scripting-engines/trace-event-python.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index ce4d1b0c386..8006978d839 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 | ||
