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.c38
1 files changed, 23 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..99c253604231 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -231,6 +231,28 @@ 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 PyObject *obj;
238 unsigned long long val;
239
240 val = read_size(event, data + field->offset, field->size);
241 if (field->flags & FIELD_IS_SIGNED) {
242 if ((long long)val >= LONG_MIN &&
243 (long long)val <= LONG_MAX)
244 obj = PyInt_FromLong(val);
245 else
246 obj = PyLong_FromLongLong(val);
247 } else {
248 if (val <= LONG_MAX)
249 obj = PyInt_FromLong(val);
250 else
251 obj = PyLong_FromUnsignedLongLong(val);
252 }
253 return obj;
254}
255
234static void python_process_tracepoint(struct perf_sample *sample, 256static void python_process_tracepoint(struct perf_sample *sample,
235 struct perf_evsel *evsel, 257 struct perf_evsel *evsel,
236 struct thread *thread, 258 struct thread *thread,
@@ -239,7 +261,6 @@ static void python_process_tracepoint(struct perf_sample *sample,
239 PyObject *handler, *retval, *context, *t, *obj, *dict = NULL; 261 PyObject *handler, *retval, *context, *t, *obj, *dict = NULL;
240 static char handler_name[256]; 262 static char handler_name[256];
241 struct format_field *field; 263 struct format_field *field;
242 unsigned long long val;
243 unsigned long s, ns; 264 unsigned long s, ns;
244 struct event_format *event; 265 struct event_format *event;
245 unsigned n = 0; 266 unsigned n = 0;
@@ -303,20 +324,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
303 offset = field->offset; 324 offset = field->offset;
304 obj = PyString_FromString((char *)data + offset); 325 obj = PyString_FromString((char *)data + offset);
305 } else { /* FIELD_IS_NUMERIC */ 326 } else { /* FIELD_IS_NUMERIC */
306 val = read_size(event, data + field->offset, 327 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 } 328 }
321 if (handler) 329 if (handler)
322 PyTuple_SetItem(t, n++, obj); 330 PyTuple_SetItem(t, n++, obj);