aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2010-05-20 04:07:53 -0400
committerJohannes Berg <johannes@sipsolutions.net>2010-05-25 07:17:02 -0400
commitce91ba442d8d909a7a9fc554338a9576d23e9239 (patch)
tree23c51ce4a21393841aadc608787709877273d37b
parent6ec8810ca35509c118ff1dc537d1bd77d7886858 (diff)
python: use pseudo-private fields
This is more idiomatic python since most other code shouldn't access these fields. Acked-by: Darren Hart <dvhltc@us.ibm.com> Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
-rw-r--r--tracecmd.py40
1 files changed, 20 insertions, 20 deletions
diff --git a/tracecmd.py b/tracecmd.py
index 1cc05bb..cf0a275 100644
--- a/tracecmd.py
+++ b/tracecmd.py
@@ -33,11 +33,11 @@ TODO: consider a complete class hierarchy of ftrace events...
33 33
34class Event(object): 34class Event(object):
35 def __init__(self, pevent, record, cpu): 35 def __init__(self, pevent, record, cpu):
36 self.pevent = pevent 36 self._pevent = pevent
37 self.rec = record 37 self._record = record
38 self.cpu = cpu 38 self.cpu = cpu
39 type = pevent_data_type(pevent, record) 39 type = pevent_data_type(pevent, record)
40 self.format = pevent_data_event_from_type(pevent, type) 40 self._format = pevent_data_event_from_type(pevent, type)
41 41
42 def __str__(self): 42 def __str__(self):
43 return "%d.%d CPU%d %s: pid=%d comm=%s type=%d" % \ 43 return "%d.%d CPU%d %s: pid=%d comm=%s type=%d" % \
@@ -45,33 +45,33 @@ class Event(object):
45 self.num_field("common_pid"), self.comm, self.type) 45 self.num_field("common_pid"), self.comm, self.type)
46 46
47 def __del__(self): 47 def __del__(self):
48 free_record(self.rec); 48 free_record(self._record);
49 49
50 50
51 # TODO: consider caching the results of the properties 51 # TODO: consider caching the results of the properties
52 @property 52 @property
53 def comm(self): 53 def comm(self):
54 return pevent_data_comm_from_pid(self.pevent, self.pid) 54 return pevent_data_comm_from_pid(self._pevent, self.pid)
55 55
56 @property 56 @property
57 def name(self): 57 def name(self):
58 return event_format_name_get(self.format) 58 return event_format_name_get(self._format)
59 59
60 @property 60 @property
61 def pid(self): 61 def pid(self):
62 return pevent_data_pid(self.pevent, self.rec) 62 return pevent_data_pid(self._pevent, self._record)
63 63
64 @property 64 @property
65 def ts(self): 65 def ts(self):
66 return record_ts_get(self.rec) 66 return record_ts_get(self._record)
67 67
68 @property 68 @property
69 def type(self): 69 def type(self):
70 return pevent_data_type(self.pevent, self.rec) 70 return pevent_data_type(self._pevent, self._record)
71 71
72 def num_field(self, name): 72 def num_field(self, name):
73 f = pevent_find_any_field(self.format, name) 73 f = pevent_find_any_field(self._format, name)
74 val = pevent_read_number_field_py(f, record_data_get(self.rec)) 74 val = pevent_read_number_field_py(f, record_data_get(self._record))
75 return val 75 return val
76 76
77 77
@@ -86,37 +86,37 @@ class Trace(object):
86 used to manage the trace and extract events from it. 86 used to manage the trace and extract events from it.
87 """ 87 """
88 def __init__(self, filename): 88 def __init__(self, filename):
89 self.handle = tracecmd_alloc(filename) 89 self._handle = tracecmd_alloc(filename)
90 90
91 if tracecmd_read_headers(self.handle): 91 if tracecmd_read_headers(self._handle):
92 raise FileFormatError("Invalid headers") 92 raise FileFormatError("Invalid headers")
93 93
94 if tracecmd_init_data(self.handle): 94 if tracecmd_init_data(self._handle):
95 raise FileFormatError("Failed to init data") 95 raise FileFormatError("Failed to init data")
96 96
97 self.pe = tracecmd_get_pevent(self.handle) 97 self._pevent = tracecmd_get_pevent(self._handle)
98 98
99 @property 99 @property
100 def cpus(self): 100 def cpus(self):
101 return tracecmd_cpus(self.handle) 101 return tracecmd_cpus(self._handle)
102 102
103 def read_event(self, cpu): 103 def read_event(self, cpu):
104 rec = tracecmd_read_data(self.handle, cpu) 104 rec = tracecmd_read_data(self._handle, cpu)
105 if rec: 105 if rec:
106 #rec.acquire() 106 #rec.acquire()
107 #rec.thisown = 1 107 #rec.thisown = 1
108 return Event(self.pe, rec, cpu) 108 return Event(self._pevent, rec, cpu)
109 return None 109 return None
110 110
111 def read_event_at(self, offset): 111 def read_event_at(self, offset):
112 res = tracecmd_read_at(self.handle, offset) 112 res = tracecmd_read_at(self._handle, offset)
113 # SWIG only returns the CPU if the record is None for some reason 113 # SWIG only returns the CPU if the record is None for some reason
114 if isinstance(res, int): 114 if isinstance(res, int):
115 return None 115 return None
116 rec,cpu = res 116 rec,cpu = res
117 #rec.acquire() 117 #rec.acquire()
118 #rec.thisown = 1 118 #rec.thisown = 1
119 ev = Event(self.pe, rec, cpu) 119 ev = Event(self._pevent, rec, cpu)
120 return ev 120 return ev
121 121
122 def peek_event(self, cpu): 122 def peek_event(self, cpu):