diff options
author | Arun Kalyanasundaram <arunkaly@google.com> | 2017-07-21 18:04:19 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-07-25 21:43:19 -0400 |
commit | 892e76b2e8c5e85e69514478e3319575a68b9770 (patch) | |
tree | 9f64e8f02f52950f3dd7af35bc877fe1b995f8d3 /tools/perf/util/scripting-engines/trace-event-python.c | |
parent | e9f9a9ca8588e58dc0800b44adc41d32f6fc813a (diff) |
perf script python: Refactor creation of perf sample dict
Move the creation of the dict containing perf_sample entries into a
helper function to enable its reuse in other sample processing routines.
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-3-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 | 94 |
1 files changed, 53 insertions, 41 deletions
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 8a8f4829d3e2..69d1b6db96f6 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c | |||
@@ -391,6 +391,57 @@ exit: | |||
391 | return pylist; | 391 | return pylist; |
392 | } | 392 | } |
393 | 393 | ||
394 | static PyObject *get_perf_sample_dict(struct perf_sample *sample, | ||
395 | struct perf_evsel *evsel, | ||
396 | struct addr_location *al, | ||
397 | PyObject *callchain) | ||
398 | { | ||
399 | PyObject *dict, *dict_sample; | ||
400 | |||
401 | dict = PyDict_New(); | ||
402 | if (!dict) | ||
403 | Py_FatalError("couldn't create Python dictionary"); | ||
404 | |||
405 | dict_sample = PyDict_New(); | ||
406 | if (!dict_sample) | ||
407 | Py_FatalError("couldn't create Python dictionary"); | ||
408 | |||
409 | pydict_set_item_string_decref(dict, "ev_name", PyString_FromString(perf_evsel__name(evsel))); | ||
410 | pydict_set_item_string_decref(dict, "attr", PyString_FromStringAndSize( | ||
411 | (const char *)&evsel->attr, sizeof(evsel->attr))); | ||
412 | |||
413 | pydict_set_item_string_decref(dict_sample, "pid", | ||
414 | PyInt_FromLong(sample->pid)); | ||
415 | pydict_set_item_string_decref(dict_sample, "tid", | ||
416 | PyInt_FromLong(sample->tid)); | ||
417 | pydict_set_item_string_decref(dict_sample, "cpu", | ||
418 | PyInt_FromLong(sample->cpu)); | ||
419 | pydict_set_item_string_decref(dict_sample, "ip", | ||
420 | PyLong_FromUnsignedLongLong(sample->ip)); | ||
421 | pydict_set_item_string_decref(dict_sample, "time", | ||
422 | PyLong_FromUnsignedLongLong(sample->time)); | ||
423 | pydict_set_item_string_decref(dict_sample, "period", | ||
424 | PyLong_FromUnsignedLongLong(sample->period)); | ||
425 | pydict_set_item_string_decref(dict, "sample", dict_sample); | ||
426 | |||
427 | pydict_set_item_string_decref(dict, "raw_buf", PyString_FromStringAndSize( | ||
428 | (const char *)sample->raw_data, sample->raw_size)); | ||
429 | pydict_set_item_string_decref(dict, "comm", | ||
430 | PyString_FromString(thread__comm_str(al->thread))); | ||
431 | if (al->map) { | ||
432 | pydict_set_item_string_decref(dict, "dso", | ||
433 | PyString_FromString(al->map->dso->name)); | ||
434 | } | ||
435 | if (al->sym) { | ||
436 | pydict_set_item_string_decref(dict, "symbol", | ||
437 | PyString_FromString(al->sym->name)); | ||
438 | } | ||
439 | |||
440 | pydict_set_item_string_decref(dict, "callchain", callchain); | ||
441 | |||
442 | return dict; | ||
443 | } | ||
444 | |||
394 | static void python_process_tracepoint(struct perf_sample *sample, | 445 | static void python_process_tracepoint(struct perf_sample *sample, |
395 | struct perf_evsel *evsel, | 446 | struct perf_evsel *evsel, |
396 | struct addr_location *al) | 447 | struct addr_location *al) |
@@ -801,7 +852,7 @@ static void python_process_general_event(struct perf_sample *sample, | |||
801 | struct perf_evsel *evsel, | 852 | struct perf_evsel *evsel, |
802 | struct addr_location *al) | 853 | struct addr_location *al) |
803 | { | 854 | { |
804 | PyObject *handler, *t, *dict, *callchain, *dict_sample; | 855 | PyObject *handler, *t, *dict, *callchain; |
805 | static char handler_name[64]; | 856 | static char handler_name[64]; |
806 | unsigned n = 0; | 857 | unsigned n = 0; |
807 | 858 | ||
@@ -819,48 +870,9 @@ static void python_process_general_event(struct perf_sample *sample, | |||
819 | if (!t) | 870 | if (!t) |
820 | Py_FatalError("couldn't create Python tuple"); | 871 | Py_FatalError("couldn't create Python tuple"); |
821 | 872 | ||
822 | dict = PyDict_New(); | ||
823 | if (!dict) | ||
824 | Py_FatalError("couldn't create Python dictionary"); | ||
825 | |||
826 | dict_sample = PyDict_New(); | ||
827 | if (!dict_sample) | ||
828 | Py_FatalError("couldn't create Python dictionary"); | ||
829 | |||
830 | pydict_set_item_string_decref(dict, "ev_name", PyString_FromString(perf_evsel__name(evsel))); | ||
831 | pydict_set_item_string_decref(dict, "attr", PyString_FromStringAndSize( | ||
832 | (const char *)&evsel->attr, sizeof(evsel->attr))); | ||
833 | |||
834 | pydict_set_item_string_decref(dict_sample, "pid", | ||
835 | PyInt_FromLong(sample->pid)); | ||
836 | pydict_set_item_string_decref(dict_sample, "tid", | ||
837 | PyInt_FromLong(sample->tid)); | ||
838 | pydict_set_item_string_decref(dict_sample, "cpu", | ||
839 | PyInt_FromLong(sample->cpu)); | ||
840 | pydict_set_item_string_decref(dict_sample, "ip", | ||
841 | PyLong_FromUnsignedLongLong(sample->ip)); | ||
842 | pydict_set_item_string_decref(dict_sample, "time", | ||
843 | PyLong_FromUnsignedLongLong(sample->time)); | ||
844 | pydict_set_item_string_decref(dict_sample, "period", | ||
845 | PyLong_FromUnsignedLongLong(sample->period)); | ||
846 | pydict_set_item_string_decref(dict, "sample", dict_sample); | ||
847 | |||
848 | pydict_set_item_string_decref(dict, "raw_buf", PyString_FromStringAndSize( | ||
849 | (const char *)sample->raw_data, sample->raw_size)); | ||
850 | pydict_set_item_string_decref(dict, "comm", | ||
851 | PyString_FromString(thread__comm_str(al->thread))); | ||
852 | if (al->map) { | ||
853 | pydict_set_item_string_decref(dict, "dso", | ||
854 | PyString_FromString(al->map->dso->name)); | ||
855 | } | ||
856 | if (al->sym) { | ||
857 | pydict_set_item_string_decref(dict, "symbol", | ||
858 | PyString_FromString(al->sym->name)); | ||
859 | } | ||
860 | |||
861 | /* ip unwinding */ | 873 | /* ip unwinding */ |
862 | callchain = python_process_callchain(sample, evsel, al); | 874 | callchain = python_process_callchain(sample, evsel, al); |
863 | pydict_set_item_string_decref(dict, "callchain", callchain); | 875 | dict = get_perf_sample_dict(sample, evsel, al, callchain); |
864 | 876 | ||
865 | PyTuple_SetItem(t, n++, dict); | 877 | PyTuple_SetItem(t, n++, dict); |
866 | if (_PyTuple_Resize(&t, n) == -1) | 878 | if (_PyTuple_Resize(&t, n) == -1) |