aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/scripting-engines/trace-event-python.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2014-07-05 05:29:32 -0400
committerIngo Molnar <mingo@kernel.org>2014-07-05 05:29:32 -0400
commit8b5b584daf3b92fc5cdc83919e64231817d2f5a7 (patch)
tree20519c481b8233a3efda947ea0c7202e4881b087 /tools/perf/util/scripting-engines/trace-event-python.c
parent432100ba2aacc2146a2b1f26e5b5ae5d6e29972a (diff)
parent8ac631cd502d6b31fd29f6d019305305b479fa3e (diff)
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf into perf/core
Pull perf/core improvements and fixes from Jiri Olsa: * Handle the num array type in python properly (Sebastian Andrzej Siewior) * Fix wrong condition for allocation failure (Jiri Olsa) * Adjust callchain based on DWARF debug info on powerpc (Sukadev Bhattiprolu) * Fix a risk for doing free on uninitialized pointer in traceevent lib (Rickard Strandqvist) Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/perf/util/scripting-engines/trace-event-python.c')
-rw-r--r--tools/perf/util/scripting-engines/trace-event-python.c57
1 files changed, 42 insertions, 15 deletions
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 1c419321f707..e55b65a65558 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -231,6 +231,47 @@ static inline struct event_format *find_cache_event(struct perf_evsel *evsel)
231 return event; 231 return event;
232} 232}
233 233
234static PyObject *get_field_numeric_entry(struct event_format *event,
235 struct format_field *field, void *data)
236{
237 bool is_array = field->flags & FIELD_IS_ARRAY;
238 PyObject *obj, *list = NULL;
239 unsigned long long val;
240 unsigned int item_size, n_items, i;
241
242 if (is_array) {
243 list = PyList_New(field->arraylen);
244 item_size = field->size / field->arraylen;
245 n_items = field->arraylen;
246 } else {
247 item_size = field->size;
248 n_items = 1;
249 }
250
251 for (i = 0; i < n_items; i++) {
252
253 val = read_size(event, data + field->offset + i * item_size,
254 item_size);
255 if (field->flags & FIELD_IS_SIGNED) {
256 if ((long long)val >= LONG_MIN &&
257 (long long)val <= LONG_MAX)
258 obj = PyInt_FromLong(val);
259 else
260 obj = PyLong_FromLongLong(val);
261 } else {
262 if (val <= LONG_MAX)
263 obj = PyInt_FromLong(val);
264 else
265 obj = PyLong_FromUnsignedLongLong(val);
266 }
267 if (is_array)
268 PyList_SET_ITEM(list, i, obj);
269 }
270 if (is_array)
271 obj = list;
272 return obj;
273}
274
234static void python_process_tracepoint(struct perf_sample *sample, 275static void python_process_tracepoint(struct perf_sample *sample,
235 struct perf_evsel *evsel, 276 struct perf_evsel *evsel,
236 struct thread *thread, 277 struct thread *thread,
@@ -239,7 +280,6 @@ static void python_process_tracepoint(struct perf_sample *sample,
239 PyObject *handler, *retval, *context, *t, *obj, *dict = NULL; 280 PyObject *handler, *retval, *context, *t, *obj, *dict = NULL;
240 static char handler_name[256]; 281 static char handler_name[256];
241 struct format_field *field; 282 struct format_field *field;
242 unsigned long long val;
243 unsigned long s, ns; 283 unsigned long s, ns;
244 struct event_format *event; 284 struct event_format *event;
245 unsigned n = 0; 285 unsigned n = 0;
@@ -303,20 +343,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
303 offset = field->offset; 343 offset = field->offset;
304 obj = PyString_FromString((char *)data + offset); 344 obj = PyString_FromString((char *)data + offset);
305 } else { /* FIELD_IS_NUMERIC */ 345 } else { /* FIELD_IS_NUMERIC */
306 val = read_size(event, data + field->offset, 346 obj = get_field_numeric_entry(event, field, data);
307 field->size);
308 if (field->flags & FIELD_IS_SIGNED) {
309 if ((long long)val >= LONG_MIN &&
310 (long long)val <= LONG_MAX)
311 obj = PyInt_FromLong(val);
312 else
313 obj = PyLong_FromLongLong(val);
314 } else {
315 if (val <= LONG_MAX)
316 obj = PyInt_FromLong(val);
317 else
318 obj = PyLong_FromUnsignedLongLong(val);
319 }
320 } 347 }
321 if (handler) 348 if (handler)
322 PyTuple_SetItem(t, n++, obj); 349 PyTuple_SetItem(t, n++, obj);