aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/scripting-engines
diff options
context:
space:
mode:
authorFeng Tang <feng.tang@intel.com>2012-08-08 05:57:53 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-08-08 11:48:02 -0400
commitfd6b858a1e110c76e701cd9972a284ed2a7bcc33 (patch)
treed512d9601692f9eacdb1a3497af50ce0173fcfe3 /tools/perf/util/scripting-engines
parent73994dc158a24df4af77d0a76c9702f120f7a6ad (diff)
perf scripts python: Pass event/thread/dso name and symbol info to event handler in python
Also as suggested by Arnaldo, pack all these parameters to a dictionary, which is more expandable for adding new parameters while keeping the compatibility for old scripts. Signed-off-by: Feng Tang <feng.tang@intel.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: David Ahern <dsahern@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Robert Richter <robert.richter@amd.com> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1344419875-21665-4-git-send-email-feng.tang@intel.com 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-python.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 24711b3536d3..7e3f57656c55 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -345,15 +345,23 @@ static void python_process_general_event(union perf_event *perf_event __unused,
345 struct machine *machine __unused, 345 struct machine *machine __unused,
346 struct addr_location *al __unused) 346 struct addr_location *al __unused)
347{ 347{
348 PyObject *handler, *retval, *t; 348 PyObject *handler, *retval, *t, *dict;
349 static char handler_name[64]; 349 static char handler_name[64];
350 unsigned n = 0; 350 unsigned n = 0;
351 void *data = sample->raw_data; 351 struct thread *thread = al->thread;
352 352
353 /*
354 * Use the MAX_FIELDS to make the function expandable, though
355 * currently there is only one itme for the tuple.
356 */
353 t = PyTuple_New(MAX_FIELDS); 357 t = PyTuple_New(MAX_FIELDS);
354 if (!t) 358 if (!t)
355 Py_FatalError("couldn't create Python tuple"); 359 Py_FatalError("couldn't create Python tuple");
356 360
361 dict = PyDict_New();
362 if (!dict)
363 Py_FatalError("couldn't create Python dictionary");
364
357 snprintf(handler_name, sizeof(handler_name), "%s", "process_event"); 365 snprintf(handler_name, sizeof(handler_name), "%s", "process_event");
358 366
359 handler = PyDict_GetItemString(main_dict, handler_name); 367 handler = PyDict_GetItemString(main_dict, handler_name);
@@ -362,11 +370,25 @@ static void python_process_general_event(union perf_event *perf_event __unused,
362 goto exit; 370 goto exit;
363 } 371 }
364 372
365 /* Pass 4 parameters: event_attr, perf_sample, raw data, thread name */ 373 PyDict_SetItemString(dict, "ev_name", PyString_FromString(perf_evsel__name(evsel)));
366 PyTuple_SetItem(t, n++, PyString_FromStringAndSize((void *)&evsel->attr, sizeof(evsel->attr))); 374 PyDict_SetItemString(dict, "attr", PyString_FromStringAndSize(
367 PyTuple_SetItem(t, n++, PyString_FromStringAndSize((void *)sample, sizeof(*sample))); 375 (const char *)&evsel->attr, sizeof(evsel->attr)));
368 PyTuple_SetItem(t, n++, PyString_FromStringAndSize(data, sample->raw_size)); 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 }
369 390
391 PyTuple_SetItem(t, n++, dict);
370 if (_PyTuple_Resize(&t, n) == -1) 392 if (_PyTuple_Resize(&t, n) == -1)
371 Py_FatalError("error resizing Python tuple"); 393 Py_FatalError("error resizing Python tuple");
372 394
@@ -374,6 +396,7 @@ static void python_process_general_event(union perf_event *perf_event __unused,
374 if (retval == NULL) 396 if (retval == NULL)
375 handler_call_die(handler_name); 397 handler_call_die(handler_name);
376exit: 398exit:
399 Py_DECREF(dict);
377 Py_DECREF(t); 400 Py_DECREF(t);
378} 401}
379 402