aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/scripting-engines/trace-event-python.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/scripting-engines/trace-event-python.c')
-rw-r--r--tools/perf/util/scripting-engines/trace-event-python.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index ff134700bf30..089438da1f7f 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 <stdbool.h> 27#include <stdbool.h>
28#include <errno.h> 28#include <errno.h>
29#include <linux/bitmap.h> 29#include <linux/bitmap.h>
30#include <linux/time64.h>
30 31
31#include "../../perf.h" 32#include "../../perf.h"
32#include "../debug.h" 33#include "../debug.h"
@@ -273,7 +274,7 @@ static PyObject *get_field_numeric_entry(struct event_format *event,
273 struct format_field *field, void *data) 274 struct format_field *field, void *data)
274{ 275{
275 bool is_array = field->flags & FIELD_IS_ARRAY; 276 bool is_array = field->flags & FIELD_IS_ARRAY;
276 PyObject *obj, *list = NULL; 277 PyObject *obj = NULL, *list = NULL;
277 unsigned long long val; 278 unsigned long long val;
278 unsigned int item_size, n_items, i; 279 unsigned int item_size, n_items, i;
279 280
@@ -386,13 +387,12 @@ exit:
386 return pylist; 387 return pylist;
387} 388}
388 389
389
390static void python_process_tracepoint(struct perf_sample *sample, 390static void python_process_tracepoint(struct perf_sample *sample,
391 struct perf_evsel *evsel, 391 struct perf_evsel *evsel,
392 struct addr_location *al) 392 struct addr_location *al)
393{ 393{
394 struct event_format *event = evsel->tp_format; 394 struct event_format *event = evsel->tp_format;
395 PyObject *handler, *context, *t, *obj, *callchain; 395 PyObject *handler, *context, *t, *obj = NULL, *callchain;
396 PyObject *dict = NULL; 396 PyObject *dict = NULL;
397 static char handler_name[256]; 397 static char handler_name[256];
398 struct format_field *field; 398 struct format_field *field;
@@ -427,8 +427,8 @@ static void python_process_tracepoint(struct perf_sample *sample,
427 if (!dict) 427 if (!dict)
428 Py_FatalError("couldn't create Python dict"); 428 Py_FatalError("couldn't create Python dict");
429 } 429 }
430 s = nsecs / NSECS_PER_SEC; 430 s = nsecs / NSEC_PER_SEC;
431 ns = nsecs - s * NSECS_PER_SEC; 431 ns = nsecs - s * NSEC_PER_SEC;
432 432
433 scripting_context->event_data = data; 433 scripting_context->event_data = data;
434 scripting_context->pevent = evsel->tp_format->pevent; 434 scripting_context->pevent = evsel->tp_format->pevent;
@@ -457,14 +457,26 @@ static void python_process_tracepoint(struct perf_sample *sample,
457 pydict_set_item_string_decref(dict, "common_callchain", callchain); 457 pydict_set_item_string_decref(dict, "common_callchain", callchain);
458 } 458 }
459 for (field = event->format.fields; field; field = field->next) { 459 for (field = event->format.fields; field; field = field->next) {
460 if (field->flags & FIELD_IS_STRING) { 460 unsigned int offset, len;
461 int offset; 461 unsigned long long val;
462
463 if (field->flags & FIELD_IS_ARRAY) {
464 offset = field->offset;
465 len = field->size;
462 if (field->flags & FIELD_IS_DYNAMIC) { 466 if (field->flags & FIELD_IS_DYNAMIC) {
463 offset = *(int *)(data + field->offset); 467 val = pevent_read_number(scripting_context->pevent,
468 data + offset, len);
469 offset = val;
470 len = offset >> 16;
464 offset &= 0xffff; 471 offset &= 0xffff;
465 } else 472 }
466 offset = field->offset; 473 if (field->flags & FIELD_IS_STRING &&
467 obj = PyString_FromString((char *)data + offset); 474 is_printable_array(data + offset, len)) {
475 obj = PyString_FromString((char *) data + offset);
476 } else {
477 obj = PyByteArray_FromStringAndSize((const char *) data + offset, len);
478 field->flags &= ~FIELD_IS_STRING;
479 }
468 } else { /* FIELD_IS_NUMERIC */ 480 } else { /* FIELD_IS_NUMERIC */
469 obj = get_field_numeric_entry(event, field, data); 481 obj = get_field_numeric_entry(event, field, data);
470 } 482 }