aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/scripting-engines/trace-event-python.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-10-01 13:28:49 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-01 13:28:49 -0400
commit7e92daaefa68e5ef1e1732e45231e73adbb724e7 (patch)
tree8e7f8ac9d82654df4c65939c6682f95510e22977 /tools/perf/util/scripting-engines/trace-event-python.c
parent7a68294278ae714ce2632a54f0f46916dca64f56 (diff)
parent1d787d37c8ff6612b8151c6dff15bfa7347bcbdf (diff)
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf update from Ingo Molnar: "Lots of changes in this cycle as well, with hundreds of commits from over 30 contributors. Most of the activity was on the tooling side. Higher level changes: - New 'perf kvm' analysis tool, from Xiao Guangrong. - New 'perf trace' system-wide tracing tool - uprobes fixes + cleanups from Oleg Nesterov. - Lots of patches to make perf build on Android out of box, from Irina Tirdea - Extend ftrace function tracing utility to be more dynamic for its users. It allows for data passing to the callback functions, as well as reading regs as if a breakpoint were to trigger at function entry. The main goal of this patch series was to allow kprobes to use ftrace as an optimized probe point when a probe is placed on an ftrace nop. With lots of help from Masami Hiramatsu, and going through lots of iterations, we finally came up with a good solution. - Add cpumask for uncore pmu, use it in 'stat', from Yan, Zheng. - Various tracing updates from Steve Rostedt - Clean up and improve 'perf sched' performance by elliminating lots of needless calls to libtraceevent. - Event group parsing support, from Jiri Olsa - UI/gtk refactorings and improvements from Namhyung Kim - Add support for non-tracepoint events in perf script python, from Feng Tang - Add --symbols to 'script', similar to the one in 'report', from Feng Tang. Infrastructure enhancements and fixes: - Convert the trace builtins to use the growing evsel/evlist tracepoint infrastructure, removing several open coded constructs like switch like series of strcmp to dispatch events, etc. Basically what had already been showcased in 'perf sched'. - Add evsel constructor for tracepoints, that uses libtraceevent just to parse the /format events file, use it in a new 'perf test' to make sure the libtraceevent format parsing regressions can be more readily caught. - Some strange errors were happening in some builds, but not on the next, reported by several people, problem was some parser related files, generated during the build, didn't had proper make deps, fix from Eric Sandeen. - Introduce struct and cache information about the environment where a perf.data file was captured, from Namhyung Kim. - Fix handling of unresolved samples when --symbols is used in 'report', from Feng Tang. - Add union member access support to 'probe', from Hyeoncheol Lee. - Fixups to die() removal, from Namhyung Kim. - Render fixes for the TUI, from Namhyung Kim. - Don't enable annotation in non symbolic view, from Namhyung Kim. - Fix pipe mode in 'report', from Namhyung Kim. - Move related stats code from stat to util/, will be used by the 'stat' kvm tool, from Xiao Guangrong. - Remove die()/exit() calls from several tools. - Resolve vdso callchains, from Jiri Olsa - Don't pass const char pointers to basename, so that we can unconditionally use libgen.h and thus avoid ifdef BIONIC lines, from David Ahern - Refactor hist formatting so that it can be reused with the GTK browser, From Namhyung Kim - Fix build for another rbtree.c change, from Adrian Hunter. - Make 'perf diff' command work with evsel hists, from Jiri Olsa. - Use the only field_sep var that is set up: symbol_conf.field_sep, fix from Jiri Olsa. - .gitignore compiled python binaries, from Namhyung Kim. - Get rid of die() in more libtraceevent places, from Namhyung Kim. - Rename libtraceevent 'private' struct member to 'priv' so that it works in C++, from Steven Rostedt - Remove lots of exit()/die() calls from tools so that the main perf exit routine can take place, from David Ahern - Fix x86 build on x86-64, from David Ahern. - {int,str,rb}list fixes from Suzuki K Poulose - perf.data header fixes from Namhyung Kim - Allow user to indicate objdump path, needed in cross environments, from Maciek Borzecki - Fix hardware cache event name generation, fix from Jiri Olsa - Add round trip test for sw, hw and cache event names, catching the problem Jiri fixed, after Jiri's patch, the test passes successfully. - Clean target should do clean for lib/traceevent too, fix from David Ahern - Check the right variable for allocation failure, fix from Namhyung Kim - Set up evsel->tp_format regardless of evsel->name being set already, fix from Namhyung Kim - Oprofile fixes from Robert Richter. - Remove perf_event_attr needless version inflation, from Jiri Olsa - Introduce libtraceevent strerror like error reporting facility, from Namhyung Kim - Add pmu mappings to perf.data header and use event names from cmd line, from Robert Richter - Fix include order for bison/flex-generated C files, from Ben Hutchings - Build fixes and documentation corrections from David Ahern - Assorted cleanups from Robert Richter - Let O= makes handle relative paths, from Steven Rostedt - perf script python fixes, from Feng Tang. - Initial bash completion support, from Frederic Weisbecker - Allow building without libelf, from Namhyung Kim. - Support DWARF CFI based unwind to have callchains when %bp based unwinding is not possible, from Jiri Olsa. - Symbol resolution fixes, while fixing support PPC64 files with an .opt ELF section was the end goal, several fixes for code that handles all architectures and cleanups are included, from Cody Schafer. - Assorted fixes for Documentation and build in 32 bit, from Robert Richter - Cache the libtraceevent event_format associated to each evsel early, so that we avoid relookups, i.e. calling pevent_find_event repeatedly when processing tracepoint events. [ This is to reduce the surface contact with libtraceevents and make clear what is that the perf tools needs from that lib: so far parsing the common and per event fields. ] - Don't stop the build if the audit libraries are not installed, fix from Namhyung Kim. - Fix bfd.h/libbfd detection with recent binutils, from Markus Trippelsdorf. - Improve warning message when libunwind devel packages not present, from Jiri Olsa" * 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (282 commits) perf trace: Add aliases for some syscalls perf probe: Print an enum type variable in "enum variable-name" format when showing accessible variables perf tools: Check libaudit availability for perf-trace builtin perf hists: Add missing period_* fields when collapsing a hist entry perf trace: New tool perf evsel: Export the event_format constructor perf evsel: Introduce rawptr() method perf tools: Use perf_evsel__newtp in the event parser perf evsel: The tracepoint constructor should store sys:name perf evlist: Introduce set_filter() method perf evlist: Renane set_filters method to apply_filters perf test: Add test to check we correctly parse and match syscall open parms perf evsel: Handle endianity in intval method perf evsel: Know if byte swap is needed perf tools: Allow handling a NULL cpu_map as meaning "all cpus" perf evsel: Improve tracepoint constructor setup tools lib traceevent: Fix error path on pevent_parse_event perf test: Fix build failure trace: Move trace event enable from fs_initcall to core_initcall tracing: Add an option for disabling markers ...
Diffstat (limited to 'tools/perf/util/scripting-engines/trace-event-python.c')
-rw-r--r--tools/perf/util/scripting-engines/trace-event-python.c113
1 files changed, 98 insertions, 15 deletions
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index ce4d1b0c3862..730c6630cba5 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -27,10 +27,12 @@
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"
33#include "../trace-event.h" 34#include "../trace-event.h"
35#include "../evsel.h"
34 36
35PyMODINIT_FUNC initperf_trace_context(void); 37PyMODINIT_FUNC initperf_trace_context(void);
36 38
@@ -194,16 +196,21 @@ static void define_event_symbols(struct event_format *event,
194 define_event_symbols(event, ev_name, args->next); 196 define_event_symbols(event, ev_name, args->next);
195} 197}
196 198
197static inline 199static inline struct event_format *find_cache_event(struct perf_evsel *evsel)
198struct event_format *find_cache_event(struct pevent *pevent, int type)
199{ 200{
200 static char ev_name[256]; 201 static char ev_name[256];
201 struct event_format *event; 202 struct event_format *event;
203 int type = evsel->attr.config;
202 204
205 /*
206 * XXX: Do we really need to cache this since now we have evsel->tp_format
207 * cached already? Need to re-read this "cache" routine that as well calls
208 * define_event_symbols() :-\
209 */
203 if (events[type]) 210 if (events[type])
204 return events[type]; 211 return events[type];
205 212
206 events[type] = event = pevent_find_event(pevent, type); 213 events[type] = event = evsel->tp_format;
207 if (!event) 214 if (!event)
208 return NULL; 215 return NULL;
209 216
@@ -214,12 +221,12 @@ struct event_format *find_cache_event(struct pevent *pevent, int type)
214 return event; 221 return event;
215} 222}
216 223
217static void python_process_event(union perf_event *perf_event __unused, 224static void python_process_tracepoint(union perf_event *perf_event
218 struct pevent *pevent, 225 __maybe_unused,
219 struct perf_sample *sample, 226 struct perf_sample *sample,
220 struct perf_evsel *evsel __unused, 227 struct perf_evsel *evsel,
221 struct machine *machine __unused, 228 struct machine *machine __maybe_unused,
222 struct thread *thread) 229 struct addr_location *al)
223{ 230{
224 PyObject *handler, *retval, *context, *t, *obj, *dict = NULL; 231 PyObject *handler, *retval, *context, *t, *obj, *dict = NULL;
225 static char handler_name[256]; 232 static char handler_name[256];
@@ -228,24 +235,22 @@ static void python_process_event(union perf_event *perf_event __unused,
228 unsigned long s, ns; 235 unsigned long s, ns;
229 struct event_format *event; 236 struct event_format *event;
230 unsigned n = 0; 237 unsigned n = 0;
231 int type;
232 int pid; 238 int pid;
233 int cpu = sample->cpu; 239 int cpu = sample->cpu;
234 void *data = sample->raw_data; 240 void *data = sample->raw_data;
235 unsigned long long nsecs = sample->time; 241 unsigned long long nsecs = sample->time;
242 struct thread *thread = al->thread;
236 char *comm = thread->comm; 243 char *comm = thread->comm;
237 244
238 t = PyTuple_New(MAX_FIELDS); 245 t = PyTuple_New(MAX_FIELDS);
239 if (!t) 246 if (!t)
240 Py_FatalError("couldn't create Python tuple"); 247 Py_FatalError("couldn't create Python tuple");
241 248
242 type = trace_parse_common_type(pevent, data); 249 event = find_cache_event(evsel);
243
244 event = find_cache_event(pevent, type);
245 if (!event) 250 if (!event)
246 die("ug! no event found for type %d", type); 251 die("ug! no event found for type %d", (int)evsel->attr.config);
247 252
248 pid = trace_parse_common_pid(pevent, data); 253 pid = raw_field_value(event, "common_pid", data);
249 254
250 sprintf(handler_name, "%s__%s", event->system, event->name); 255 sprintf(handler_name, "%s__%s", event->system, event->name);
251 256
@@ -290,7 +295,7 @@ static void python_process_event(union perf_event *perf_event __unused,
290 offset = field->offset; 295 offset = field->offset;
291 obj = PyString_FromString((char *)data + offset); 296 obj = PyString_FromString((char *)data + offset);
292 } else { /* FIELD_IS_NUMERIC */ 297 } else { /* FIELD_IS_NUMERIC */
293 val = read_size(pevent, data + field->offset, 298 val = read_size(event, data + field->offset,
294 field->size); 299 field->size);
295 if (field->flags & FIELD_IS_SIGNED) { 300 if (field->flags & FIELD_IS_SIGNED) {
296 if ((long long)val >= LONG_MIN && 301 if ((long long)val >= LONG_MIN &&
@@ -335,6 +340,84 @@ static void python_process_event(union perf_event *perf_event __unused,
335 Py_DECREF(t); 340 Py_DECREF(t);
336} 341}
337 342
343static void python_process_general_event(union perf_event *perf_event
344 __maybe_unused,
345 struct perf_sample *sample,
346 struct perf_evsel *evsel,
347 struct machine *machine __maybe_unused,
348 struct addr_location *al)
349{
350 PyObject *handler, *retval, *t, *dict;
351 static char handler_name[64];
352 unsigned n = 0;
353 struct thread *thread = al->thread;
354
355 /*
356 * Use the MAX_FIELDS to make the function expandable, though
357 * currently there is only one item for the tuple.
358 */
359 t = PyTuple_New(MAX_FIELDS);
360 if (!t)
361 Py_FatalError("couldn't create Python tuple");
362
363 dict = PyDict_New();
364 if (!dict)
365 Py_FatalError("couldn't create Python dictionary");
366
367 snprintf(handler_name, sizeof(handler_name), "%s", "process_event");
368
369 handler = PyDict_GetItemString(main_dict, handler_name);
370 if (!handler || !PyCallable_Check(handler))
371 goto exit;
372
373 PyDict_SetItemString(dict, "ev_name", PyString_FromString(perf_evsel__name(evsel)));
374 PyDict_SetItemString(dict, "attr", PyString_FromStringAndSize(
375 (const char *)&evsel->attr, sizeof(evsel->attr)));
376 PyDict_SetItemString(dict, "sample", PyString_FromStringAndSize(
377 (const char *)sample, sizeof(*sample)));
378 PyDict_SetItemString(dict, "raw_buf", PyString_FromStringAndSize(
379 (const char *)sample->raw_data, sample->raw_size));
380 PyDict_SetItemString(dict, "comm",
381 PyString_FromString(thread->comm));
382 if (al->map) {
383 PyDict_SetItemString(dict, "dso",
384 PyString_FromString(al->map->dso->name));
385 }
386 if (al->sym) {
387 PyDict_SetItemString(dict, "symbol",
388 PyString_FromString(al->sym->name));
389 }
390
391 PyTuple_SetItem(t, n++, dict);
392 if (_PyTuple_Resize(&t, n) == -1)
393 Py_FatalError("error resizing Python tuple");
394
395 retval = PyObject_CallObject(handler, t);
396 if (retval == NULL)
397 handler_call_die(handler_name);
398exit:
399 Py_DECREF(dict);
400 Py_DECREF(t);
401}
402
403static void python_process_event(union perf_event *perf_event,
404 struct perf_sample *sample,
405 struct perf_evsel *evsel,
406 struct machine *machine,
407 struct addr_location *al)
408{
409 switch (evsel->attr.type) {
410 case PERF_TYPE_TRACEPOINT:
411 python_process_tracepoint(perf_event, sample, evsel,
412 machine, al);
413 break;
414 /* Reserve for future process_hw/sw/raw APIs */
415 default:
416 python_process_general_event(perf_event, sample, evsel,
417 machine, al);
418 }
419}
420
338static int run_start_sub(void) 421static int run_start_sub(void)
339{ 422{
340 PyObject *handler, *retval; 423 PyObject *handler, *retval;