diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/perf/util/scripting-engines/trace-event-python.c | 35 |
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); |
| 376 | exit: | 398 | exit: |
| 399 | Py_DECREF(dict); | ||
| 377 | Py_DECREF(t); | 400 | Py_DECREF(t); |
| 378 | } | 401 | } |
| 379 | 402 | ||
