perf script: Provide additional sample information on generic events
authorJoseph Schuchart <joseph.schuchart@tu-dresden.de>
Thu, 10 Jul 2014 11:50:56 +0000 (13:50 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 16 Jul 2014 20:57:33 +0000 (17:57 -0300)
To python scripts, including pid, tid, and cpu for which the event was
recorded.

At the moment, the pointer to the sample struct is passed to scripts,
which seems to be of little use.

The patch puts this information in dictionaries for easy access by
Python scripts.

Signed-off-by: Joseph Schuchart <joseph.schuchart@tu-dresden.de>
Acked-by: Thomas Ilsche <thomas.ilsche@tu-dresden.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Thomas Ilsche <thomas.ilsche@tu-dresden.de>
Link: http://lkml.kernel.org/r/53BE7E20.8080500@tu-dresden.de
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/scripting-engines/trace-event-python.c

index cf65404472cbdbae5a7a331d18a844a4db07e0fb..b366b48646ca5bce9a192213dc9b313dc2f8baaf 100644 (file)
@@ -473,7 +473,7 @@ static void python_process_general_event(struct perf_sample *sample,
                                         struct thread *thread,
                                         struct addr_location *al)
 {
-       PyObject *handler, *retval, *t, *dict, *callchain;
+       PyObject *handler, *retval, *t, *dict, *callchain, *dict_sample;
        static char handler_name[64];
        unsigned n = 0;
 
@@ -489,6 +489,10 @@ static void python_process_general_event(struct perf_sample *sample,
        if (!dict)
                Py_FatalError("couldn't create Python dictionary");
 
+       dict_sample = PyDict_New();
+       if (!dict_sample)
+               Py_FatalError("couldn't create Python dictionary");
+
        snprintf(handler_name, sizeof(handler_name), "%s", "process_event");
 
        handler = PyDict_GetItemString(main_dict, handler_name);
@@ -498,8 +502,21 @@ static void python_process_general_event(struct perf_sample *sample,
        pydict_set_item_string_decref(dict, "ev_name", PyString_FromString(perf_evsel__name(evsel)));
        pydict_set_item_string_decref(dict, "attr", PyString_FromStringAndSize(
                        (const char *)&evsel->attr, sizeof(evsel->attr)));
-       pydict_set_item_string_decref(dict, "sample", PyString_FromStringAndSize(
-                       (const char *)sample, sizeof(*sample)));
+
+       pydict_set_item_string_decref(dict_sample, "pid",
+                       PyInt_FromLong(sample->pid));
+       pydict_set_item_string_decref(dict_sample, "tid",
+                       PyInt_FromLong(sample->tid));
+       pydict_set_item_string_decref(dict_sample, "cpu",
+                       PyInt_FromLong(sample->cpu));
+       pydict_set_item_string_decref(dict_sample, "ip",
+                       PyLong_FromUnsignedLongLong(sample->ip));
+       pydict_set_item_string_decref(dict_sample, "time",
+                       PyLong_FromUnsignedLongLong(sample->time));
+       pydict_set_item_string_decref(dict_sample, "period",
+                       PyLong_FromUnsignedLongLong(sample->period));
+       pydict_set_item_string_decref(dict, "sample", dict_sample);
+
        pydict_set_item_string_decref(dict, "raw_buf", PyString_FromStringAndSize(
                        (const char *)sample->raw_data, sample->raw_size));
        pydict_set_item_string_decref(dict, "comm",