From: Darren Hart <dvhltc@us.ibm.com>
To: Steven Rostedt <rostedt@goodmis.org>,
"lkml, " <linux-kernel@vger.kernel.org>
Subject: [PATCH] trace-cmd: Cleanup 64-bit handling for python wrapper
Date: Mon, 28 Dec 2009 09:59:55 -0800 [thread overview]
Message-ID: <4B38F21B.2020504@us.ibm.com> (raw)
>From 45afc359aa81cbce7a5ea559dc9625489d343f5f Mon Sep 17 00:00:00 2001
From: Darren Hart <dvhltc@us.ibm.com>
Date: Mon, 28 Dec 2009 09:36:30 -0800
Subject: [PATCH] trace-cmd: Cleanup 64-bit handling for python wrapper
Wrap pevent_read_number_field() with a more intelligent wrapper that
returns None on error and a python long on success. Eliminate the hi/lo
64 bit marshalling junk.
Use a typemap to get automatic struct accessors (ie record_ts_get()) to
return a python long for unsigned long long fields rather than
truncating to 32-bits.
Signed-off-by: Darren Hart <dvhltc@us.ibm.com>
---
ctracecmd.i | 20 +++++++++++---------
tracecmd.py | 15 +++------------
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/ctracecmd.i b/ctracecmd.i
index 20a681c..4b17327 100644
--- a/ctracecmd.i
+++ b/ctracecmd.i
@@ -6,19 +6,21 @@
#include "trace-cmd.h"
%}
-/* typemaps must come before the implementation of wrapped functions */
-extern int pevent_read_number_field_32(struct format_field *f, void *data,
- unsigned long *OUTPUT, unsigned long *OUTPUT);
+%typemap(out) unsigned long long {
+$result = PyLong_FromUnsignedLongLong((unsigned long long) $1);
+}
%inline %{
-int pevent_read_number_field_32(struct format_field *f, void *data, unsigned long *hi, unsigned long *lo)
+PyObject *pevent_read_number_field_py(struct format_field *f, void *data)
{
- unsigned long long val64;
+ unsigned long long val;
int ret;
- ret = pevent_read_number_field(f, data, &val64);
- *hi = (unsigned long)(val64>>32);
- *lo = (unsigned long)((val64<<32)>>32);
- return ret;
+
+ ret = pevent_read_number_field(f, data, &val);
+ if (ret)
+ Py_RETURN_NONE;
+ else
+ return PyLong_FromUnsignedLongLong(val);
}
%}
diff --git a/tracecmd.py b/tracecmd.py
index 6520a48..f9a2708 100644
--- a/tracecmd.py
+++ b/tracecmd.py
@@ -31,13 +31,6 @@ and it is recommended applications not use it directly.
TODO: consider a complete class hierarchy of ftrace events...
"""
-def _pevent_read_number_field(field, data):
- ret,hi,lo = pevent_read_number_field_32(field, data)
- if ret == 0:
- return ret,long(long(hi).__lshift__(32)+lo)
- return ret,None
-
-
class Event(object):
def __init__(self, trace, record):
self.trace = trace
@@ -46,8 +39,8 @@ class Event(object):
self.ec = pevent_data_event_from_type(trace.pe, type)
def __str__(self):
- return "%f %s: pid=%d comm=%s type=%d" % \
- (self.ts, self.name, self.num_field("common_pid"), self.comm, self.type)
+ return "%d.%d %s: pid=%d comm=%s type=%d" % \
+ (self.ts/1000000000, self.ts%1000000000, self.name, self.num_field("common_pid"), self.comm, self.type)
# TODO: consider caching the results of the properties
@@ -65,7 +58,6 @@ class Event(object):
@property
def ts(self):
- # FIXME: this currently returns a float instead of a 64bit nsec value
return record_ts_get(self.rec)
@property
@@ -73,9 +65,8 @@ class Event(object):
return pevent_data_type(self.trace.pe, self.rec)
def num_field(self, name):
- # FIXME: need to find an elegant way to handle 64bit fields
f = pevent_find_any_field(self.ec, name)
- ret,val = _pevent_read_number_field(f, record_data_get(self.rec))
+ val = pevent_read_number_field_py(f, record_data_get(self.rec))
return val
--
1.6.3.3
--
Darren Hart
IBM Linux Technology Center
Real-Time Linux Team
reply other threads:[~2009-12-28 18:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=4B38F21B.2020504@us.ibm.com \
--to=dvhltc@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.