aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren Hart <dvhltc@us.ibm.com>2009-12-28 20:23:03 -0500
committerDarren Hart <dvhltc@us.ibm.com>2009-12-30 12:22:40 -0500
commit55e9ea135e0d869430f4686633744ed093bd77ad (patch)
tree86e7ac1050c1f7da4c3d08e97b8321f5ef24a443
parente18c8f43f1a250a09675245d733404e2f2659cad (diff)
trace-cmd: Update tracecmd.py for tracecmd_open API change
Signed-off-by: Darren Hart <dvhltc@us.ibm.com>
-rw-r--r--tracecmd.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/tracecmd.py b/tracecmd.py
index f9a2708..fdcda76 100644
--- a/tracecmd.py
+++ b/tracecmd.py
@@ -32,15 +32,17 @@ TODO: consider a complete class hierarchy of ftrace events...
32""" 32"""
33 33
34class Event(object): 34class Event(object):
35 def __init__(self, trace, record): 35 def __init__(self, trace, record, cpu):
36 self.trace = trace 36 self.trace = trace
37 self.rec = record 37 self.rec = record
38 self.cpu = cpu
38 type = pevent_data_type(trace.pe, record) 39 type = pevent_data_type(trace.pe, record)
39 self.ec = pevent_data_event_from_type(trace.pe, type) 40 self.format = pevent_data_event_from_type(trace.pe, type)
40 41
41 def __str__(self): 42 def __str__(self):
42 return "%d.%d %s: pid=%d comm=%s type=%d" % \ 43 return "%d.%d CPU%d %s: pid=%d comm=%s type=%d" % \
43 (self.ts/1000000000, self.ts%1000000000, self.name, self.num_field("common_pid"), self.comm, self.type) 44 (self.ts/1000000000, self.ts%1000000000, self.cpu, self.name,
45 self.num_field("common_pid"), self.comm, self.type)
44 46
45 47
46 # TODO: consider caching the results of the properties 48 # TODO: consider caching the results of the properties
@@ -50,7 +52,7 @@ class Event(object):
50 52
51 @property 53 @property
52 def name(self): 54 def name(self):
53 return event_name_get(self.ec) 55 return event_format_name_get(self.format)
54 56
55 @property 57 @property
56 def pid(self): 58 def pid(self):
@@ -65,7 +67,7 @@ class Event(object):
65 return pevent_data_type(self.trace.pe, self.rec) 67 return pevent_data_type(self.trace.pe, self.rec)
66 68
67 def num_field(self, name): 69 def num_field(self, name):
68 f = pevent_find_any_field(self.ec, name) 70 f = pevent_find_any_field(self.format, name)
69 val = pevent_read_number_field_py(f, record_data_get(self.rec)) 71 val = pevent_read_number_field_py(f, record_data_get(self.rec))
70 return val 72 return val
71 73
@@ -82,9 +84,7 @@ class Trace(object):
82 self.pe = None 84 self.pe = None
83 85
84 try: 86 try:
85 file = open(filename) 87 self.handle = tracecmd_open(filename)
86 self.handle = tracecmd_open(file.fileno())
87 print "self.handle: ", self.handle
88 #FIXME: check if these throw exceptions automatically or if we have 88 #FIXME: check if these throw exceptions automatically or if we have
89 # to check return codes manually 89 # to check return codes manually
90 tracecmd_read_headers(self.handle) 90 tracecmd_read_headers(self.handle)
@@ -100,9 +100,16 @@ class Trace(object):
100 def read_event(self, cpu): 100 def read_event(self, cpu):
101 rec = tracecmd_read_data(self.handle, cpu) 101 rec = tracecmd_read_data(self.handle, cpu)
102 if rec: 102 if rec:
103 return Event(self, rec) 103 return Event(self, rec, cpu)
104 return None 104 return None
105 105
106 def read_event_at(self, offset):
107 res = tracecmd_read_at(self.handle, offset)
108 # SWIG only returns the CPU if the record is None for some reason
109 if isinstance(res, int):
110 return None
111 return Event(self, res[0], res[1])
112
106 def peek_event(self, cpu): 113 def peek_event(self, cpu):
107 pass 114 pass
108 115