From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: linux-kernel@vger.kernel.org
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Tom Zanussi <tzanussi@gmail.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: [PATCH 1/2] perf script: move the number processing into its own function
Date: Tue, 27 May 2014 18:14:33 +0200 [thread overview]
Message-ID: <1401207274-8170-1-git-send-email-bigeasy@linutronix.de> (raw)
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>
---
.../util/scripting-engines/trace-event-python.c | 38 +++++++++++++---------
1 file 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 cd9774d..aa11790 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -230,6 +230,28 @@ static inline struct event_format *find_cache_event(struct perf_evsel *evsel)
return event;
}
+static PyObject *get_field_numeric_entry(struct event_format *event,
+ struct format_field *field, void *data)
+{
+ PyObject *obj;
+ unsigned long long val;
+
+ val = read_size(event, data + field->offset, field->size);
+ if (field->flags & FIELD_IS_SIGNED) {
+ if ((long long)val >= LONG_MIN &&
+ (long long)val <= LONG_MAX)
+ obj = PyInt_FromLong(val);
+ else
+ obj = PyLong_FromLongLong(val);
+ } else {
+ if (val <= LONG_MAX)
+ obj = PyInt_FromLong(val);
+ else
+ obj = PyLong_FromUnsignedLongLong(val);
+ }
+ return obj;
+}
+
static void python_process_tracepoint(struct perf_sample *sample,
struct perf_evsel *evsel,
struct thread *thread,
@@ -238,7 +260,6 @@ static void python_process_tracepoint(struct perf_sample *sample,
PyObject *handler, *retval, *context, *t, *obj, *dict = NULL;
static char handler_name[256];
struct format_field *field;
- unsigned long long val;
unsigned long s, ns;
struct event_format *event;
unsigned n = 0;
@@ -302,20 +323,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
offset = field->offset;
obj = PyString_FromString((char *)data + offset);
} else { /* FIELD_IS_NUMERIC */
- val = read_size(event, data + field->offset,
- field->size);
- if (field->flags & FIELD_IS_SIGNED) {
- if ((long long)val >= LONG_MIN &&
- (long long)val <= LONG_MAX)
- obj = PyInt_FromLong(val);
- else
- obj = PyLong_FromLongLong(val);
- } else {
- if (val <= LONG_MAX)
- obj = PyInt_FromLong(val);
- else
- obj = PyLong_FromUnsignedLongLong(val);
- }
+ obj = get_field_numeric_entry(event, field, data);
}
if (handler)
PyTuple_SetItem(t, n++, obj);
--
2.0.0.rc4
next reply other threads:[~2014-05-27 16:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-27 16:14 Sebastian Andrzej Siewior [this message]
2014-05-27 16:14 ` [PATCH 2/2] perf script: handle the num array type in python properly Sebastian Andrzej Siewior
2014-05-29 4:43 ` Namhyung Kim
2014-05-30 9:39 ` Sebastian Andrzej Siewior
2014-05-29 4:44 ` [PATCH] perf script/python: Print array argument as string Namhyung Kim
2014-06-03 18:55 ` Jiri Olsa
2014-06-12 12:01 ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-06-26 15:37 ` Sebastian Andrzej Siewior
2014-06-26 19:22 ` Jiri Olsa
2014-05-29 4:39 ` [PATCH 1/2] perf script: move the number processing into its own function Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1401207274-8170-1-git-send-email-bigeasy@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=acme@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tzanussi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®