diff options
author | Arun Kalyanasundaram <arunkaly@google.com> | 2017-07-21 18:04:20 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-07-25 21:43:19 -0400 |
commit | 74ec14f3893c3065053b91cec850cffa2d565e0a (patch) | |
tree | 59bb340703d16f11b1c3795596ac7f1d8a527840 /tools/perf/util/scripting-engines/trace-event-python.c | |
parent | 892e76b2e8c5e85e69514478e3319575a68b9770 (diff) |
perf script python: Add sample_read to dict
Provide time_enabled, time_running and counter value in the perf_sample
dict.
Signed-off-by: Arun Kalyanasundaram <arunkaly@google.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Carrillo-Cisneros <davidcc@google.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Seongjae Park <sj38.park@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20170721220422.63962-4-arunkaly@google.com
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 | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 69d1b6db96f6..55a45784c910 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c | |||
@@ -391,6 +391,56 @@ exit: | |||
391 | return pylist; | 391 | return pylist; |
392 | } | 392 | } |
393 | 393 | ||
394 | static PyObject *get_sample_value_as_tuple(struct sample_read_value *value) | ||
395 | { | ||
396 | PyObject *t; | ||
397 | |||
398 | t = PyTuple_New(2); | ||
399 | if (!t) | ||
400 | Py_FatalError("couldn't create Python tuple"); | ||
401 | PyTuple_SetItem(t, 0, PyLong_FromUnsignedLongLong(value->id)); | ||
402 | PyTuple_SetItem(t, 1, PyLong_FromUnsignedLongLong(value->value)); | ||
403 | return t; | ||
404 | } | ||
405 | |||
406 | static void set_sample_read_in_dict(PyObject *dict_sample, | ||
407 | struct perf_sample *sample, | ||
408 | struct perf_evsel *evsel) | ||
409 | { | ||
410 | u64 read_format = evsel->attr.read_format; | ||
411 | PyObject *values; | ||
412 | unsigned int i; | ||
413 | |||
414 | if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) { | ||
415 | pydict_set_item_string_decref(dict_sample, "time_enabled", | ||
416 | PyLong_FromUnsignedLongLong(sample->read.time_enabled)); | ||
417 | } | ||
418 | |||
419 | if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) { | ||
420 | pydict_set_item_string_decref(dict_sample, "time_running", | ||
421 | PyLong_FromUnsignedLongLong(sample->read.time_running)); | ||
422 | } | ||
423 | |||
424 | if (read_format & PERF_FORMAT_GROUP) | ||
425 | values = PyList_New(sample->read.group.nr); | ||
426 | else | ||
427 | values = PyList_New(1); | ||
428 | |||
429 | if (!values) | ||
430 | Py_FatalError("couldn't create Python list"); | ||
431 | |||
432 | if (read_format & PERF_FORMAT_GROUP) { | ||
433 | for (i = 0; i < sample->read.group.nr; i++) { | ||
434 | PyObject *t = get_sample_value_as_tuple(&sample->read.group.values[i]); | ||
435 | PyList_SET_ITEM(values, i, t); | ||
436 | } | ||
437 | } else { | ||
438 | PyObject *t = get_sample_value_as_tuple(&sample->read.one); | ||
439 | PyList_SET_ITEM(values, 0, t); | ||
440 | } | ||
441 | pydict_set_item_string_decref(dict_sample, "values", values); | ||
442 | } | ||
443 | |||
394 | static PyObject *get_perf_sample_dict(struct perf_sample *sample, | 444 | static PyObject *get_perf_sample_dict(struct perf_sample *sample, |
395 | struct perf_evsel *evsel, | 445 | struct perf_evsel *evsel, |
396 | struct addr_location *al, | 446 | struct addr_location *al, |
@@ -422,6 +472,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, | |||
422 | PyLong_FromUnsignedLongLong(sample->time)); | 472 | PyLong_FromUnsignedLongLong(sample->time)); |
423 | pydict_set_item_string_decref(dict_sample, "period", | 473 | pydict_set_item_string_decref(dict_sample, "period", |
424 | PyLong_FromUnsignedLongLong(sample->period)); | 474 | PyLong_FromUnsignedLongLong(sample->period)); |
475 | set_sample_read_in_dict(dict_sample, sample, evsel); | ||
425 | pydict_set_item_string_decref(dict, "sample", dict_sample); | 476 | pydict_set_item_string_decref(dict, "sample", dict_sample); |
426 | 477 | ||
427 | pydict_set_item_string_decref(dict, "raw_buf", PyString_FromStringAndSize( | 478 | pydict_set_item_string_decref(dict, "raw_buf", PyString_FromStringAndSize( |