aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/scripting-engines
diff options
context:
space:
mode:
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>2014-05-27 12:14:33 -0400
committerJiri Olsa <jolsa@kernel.org>2014-06-27 05:14:57 -0400
commit33058b948e545a911e388e69b8be7274da158fb6 (patch)
tree46f9908806f5f891983b5eb09524b9d521fb450c /tools/perf/util/scripting-engines
parentd180ac14a95d738c2d2622db82c2212a8f998200 (diff)
perf script: Move the number processing into its own function
I was going to change something here and the result was so much on the right side of the screen that I decided to move that piece into its own function. This patch should make no function change except the moving the code into its own function. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Acked-by: Namhyung Kim <namhyung@kernel.org> Link: http://lkml.kernel.org/n/1401207274-8170-1-git-send-email-bigeasy@linutronix.de Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Diffstat (limited to 'tools/perf/util/scripting-engines')
-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);