diff options
author | Jiri Olsa <jolsa@kernel.org> | 2014-10-26 18:44:05 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-11-06 15:44:06 -0500 |
commit | adf5bcf39583c4db1bf30069f8957400e61ccb18 (patch) | |
tree | ecebfc2cdf1d556df36dbe87662b96e56d001dd7 /tools/perf/util/scripting-engines/trace-event-python.c | |
parent | cdae2d1e936457bf72673cb77e7f5f4b9d4c451e (diff) |
perf script python: Removing event cache as it's no longer needed
We don't need to maintain cache of 'struct event_format' objects.
Currently the 'struct perf_evsel' holds this reference already.
Adding events_defined bitmap to keep track of defined events, which is
much cheaper than array of pointers.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1414363445-22370-3-git-send-email-jolsa@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 | 34 |
1 files changed, 6 insertions, 28 deletions
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 118bc62850a8..d808a328f4dc 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <string.h> | 26 | #include <string.h> |
27 | #include <stdbool.h> | 27 | #include <stdbool.h> |
28 | #include <errno.h> | 28 | #include <errno.h> |
29 | #include <linux/bitmap.h> | ||
29 | 30 | ||
30 | #include "../../perf.h" | 31 | #include "../../perf.h" |
31 | #include "../debug.h" | 32 | #include "../debug.h" |
@@ -46,7 +47,7 @@ PyMODINIT_FUNC initperf_trace_context(void); | |||
46 | #define FTRACE_MAX_EVENT \ | 47 | #define FTRACE_MAX_EVENT \ |
47 | ((1 << (sizeof(unsigned short) * 8)) - 1) | 48 | ((1 << (sizeof(unsigned short) * 8)) - 1) |
48 | 49 | ||
49 | struct event_format *events[FTRACE_MAX_EVENT]; | 50 | static DECLARE_BITMAP(events_defined, FTRACE_MAX_EVENT); |
50 | 51 | ||
51 | #define MAX_FIELDS 64 | 52 | #define MAX_FIELDS 64 |
52 | #define N_COMMON_FIELDS 7 | 53 | #define N_COMMON_FIELDS 7 |
@@ -255,31 +256,6 @@ static void define_event_symbols(struct event_format *event, | |||
255 | define_event_symbols(event, ev_name, args->next); | 256 | define_event_symbols(event, ev_name, args->next); |
256 | } | 257 | } |
257 | 258 | ||
258 | static inline struct event_format *find_cache_event(struct perf_evsel *evsel) | ||
259 | { | ||
260 | static char ev_name[256]; | ||
261 | struct event_format *event; | ||
262 | int type = evsel->attr.config; | ||
263 | |||
264 | /* | ||
265 | * XXX: Do we really need to cache this since now we have evsel->tp_format | ||
266 | * cached already? Need to re-read this "cache" routine that as well calls | ||
267 | * define_event_symbols() :-\ | ||
268 | */ | ||
269 | if (events[type]) | ||
270 | return events[type]; | ||
271 | |||
272 | events[type] = event = evsel->tp_format; | ||
273 | if (!event) | ||
274 | return NULL; | ||
275 | |||
276 | sprintf(ev_name, "%s__%s", event->system, event->name); | ||
277 | |||
278 | define_event_symbols(event, ev_name, event->print_fmt.args); | ||
279 | |||
280 | return event; | ||
281 | } | ||
282 | |||
283 | static PyObject *get_field_numeric_entry(struct event_format *event, | 259 | static PyObject *get_field_numeric_entry(struct event_format *event, |
284 | struct format_field *field, void *data) | 260 | struct format_field *field, void *data) |
285 | { | 261 | { |
@@ -403,12 +379,12 @@ static void python_process_tracepoint(struct perf_sample *sample, | |||
403 | struct thread *thread, | 379 | struct thread *thread, |
404 | struct addr_location *al) | 380 | struct addr_location *al) |
405 | { | 381 | { |
382 | struct event_format *event = evsel->tp_format; | ||
406 | PyObject *handler, *context, *t, *obj, *callchain; | 383 | PyObject *handler, *context, *t, *obj, *callchain; |
407 | PyObject *dict = NULL; | 384 | PyObject *dict = NULL; |
408 | static char handler_name[256]; | 385 | static char handler_name[256]; |
409 | struct format_field *field; | 386 | struct format_field *field; |
410 | unsigned long s, ns; | 387 | unsigned long s, ns; |
411 | struct event_format *event; | ||
412 | unsigned n = 0; | 388 | unsigned n = 0; |
413 | int pid; | 389 | int pid; |
414 | int cpu = sample->cpu; | 390 | int cpu = sample->cpu; |
@@ -420,7 +396,6 @@ static void python_process_tracepoint(struct perf_sample *sample, | |||
420 | if (!t) | 396 | if (!t) |
421 | Py_FatalError("couldn't create Python tuple"); | 397 | Py_FatalError("couldn't create Python tuple"); |
422 | 398 | ||
423 | event = find_cache_event(evsel); | ||
424 | if (!event) | 399 | if (!event) |
425 | die("ug! no event found for type %d", (int)evsel->attr.config); | 400 | die("ug! no event found for type %d", (int)evsel->attr.config); |
426 | 401 | ||
@@ -428,6 +403,9 @@ static void python_process_tracepoint(struct perf_sample *sample, | |||
428 | 403 | ||
429 | sprintf(handler_name, "%s__%s", event->system, event->name); | 404 | sprintf(handler_name, "%s__%s", event->system, event->name); |
430 | 405 | ||
406 | if (!test_and_set_bit(event->id, events_defined)) | ||
407 | define_event_symbols(event, handler_name, event->print_fmt.args); | ||
408 | |||
431 | handler = get_handler(handler_name); | 409 | handler = get_handler(handler_name); |
432 | if (!handler) { | 410 | if (!handler) { |
433 | dict = PyDict_New(); | 411 | dict = PyDict_New(); |