* [PATCH] trace-cmd: Cleanup 64-bit handling for python wrapper
@ 2009-12-28 17:59 Darren Hart
0 siblings, 0 replies; only message in thread
From: Darren Hart @ 2009-12-28 17:59 UTC (permalink / raw)
To: Steven Rostedt, lkml,
>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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2009-12-28 18:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-28 17:59 [PATCH] trace-cmd: Cleanup 64-bit handling for python wrapper Darren Hart
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.