3 """TSAR Event type definitions"""
8 #pylint: disable=C0103,R0903
12 """Event base class"""
30 """Get name for event type"""
31 syscall_names = ["INV", "SYS", "PF",
32 "SWIFI", "FOO", "TRAP",
33 "START", "STOP", "LOCK", "SHML"]
34 return syscall_names[event]
36 def __init__(self, time=0, typ=0, utcb=0, uid=None):
41 (self.id2, self.id1) = ("", self.utcb)
43 (self.id2, self.id1) = uid.split(":")
46 """Unique event source ID (NOT unique event ID!)"""
47 return "%s:%s" % (self.id1, self.id2)
51 return "%d [%8x|%5s] (%s,%s) " % (self.timestamp, self.utcb,
52 Event.eventname(self.type),
60 """Pretty-print event"""
61 return " %d" % self.type
64 class SyscallEvent(Event):
65 """Romain system call event"""
66 def __init__(self, raw, time=0, utcb=0, uid=None):
67 Event.__init__(self, time, Event.SYSCALL_TYPE, utcb, uid)
68 (self.eip, self.label, ) = struct.unpack_from("II",
72 return Event.__repr__(self) + " SYSCALL %08x, ret to %08x" % \
73 (self.label, self.eip)
76 return ["SYSCALL %08x" % (self.label),
77 " ret -> %08x" % (self.eip)]
80 class PagefaultEvent(Event):
81 """Page fault event"""
82 def __init__(self, raw, time=0, utcb=0, uid=None):
83 Event.__init__(self, time, Event.PAGEFAULT_TYPE, utcb, uid)
84 (self.writepf, ) = struct.unpack_from("B", raw[Event.HEADSIZE:])
87 self.remote) = struct.unpack_from("III", raw[Event.HEADSIZE + 1:])
91 res = Event.__repr__(self)
94 res += "r pf @ %08x -> %08x" % (self.local, self.remote)
100 res += ["wr pf @ 0x%x" % self.pfa]
102 res += ["r pf @ 0x%x" % self.pfa]
103 res += ["%x -> %x" % (self.local, self.remote)]
107 class SwifiEvent(Event):
109 def __init__(self, raw, time=0, utcb=0, uid=None):
110 Event.__init__(self, time, Event.SWIFI_TYPE, utcb, uid)
116 class FooEvent(Event):
118 def __init__(self, raw, time=0, utcb=0, uid=None):
119 Event.__init__(self, time, Event.FOO_TYPE, utcb, uid)
120 (self.is_start, ) = struct.unpack_from("I", raw[Event.HEADSIZE:])
123 res = Event.__repr__(self)
124 if self.is_start == 0:
134 class TrapEvent(Event):
135 """Generic trap event"""
138 def __init__(self, raw, time=0, utcb=0, uid=None):
139 Event.__init__(self, time, Event.TRAP_TYPE, utcb, uid)
140 (self.is_start, ) = struct.unpack_from("B", raw[Event.HEADSIZE:])
141 (self.trapaddr, self.trapno, ) = \
142 struct.unpack_from("II", raw[Event.HEADSIZE + 1:])
144 #print "S %d T %d" % (self.is_start, self.trapno)
147 res = Event.__repr__(self)
148 if self.is_start == 1:
149 res += " start, trapno %x" % self.trapno
156 return ["\033[33mTRAP %x @ %08x\033[0m" %
157 (self.trapno, self.trapaddr)]
159 return ["--- TRAP END ---"]
162 class ThreadStartEvent(Event):
163 """Thread start event"""
165 def __init__(self, raw, time=0, utcb=0, uid=None):
166 Event.__init__(self, time, Event.THREAD_START_TYPE, utcb, uid)
169 res = Event.__repr__(self)
170 res += "Thread::Start"
174 return ["Thread::Start"]
177 class ThreadStopEvent(Event):
178 """Thread end event"""
180 def __init__(self, raw, time=0, utcb=0, uid=None):
181 Event.__init__(self, time, Event.THREAD_STOP_TYPE, utcb, uid)
184 res = Event.__repr__(self)
185 res += "Thread::Exit"
189 return ["Thread::Exit"]
192 class LockingEvent(Event):
193 """Lock interception event"""
194 def __init__(self, raw, time=0, utcb=0, uid=None):
195 Event.__init__(self, time, Event.LOCKING_TYPE, utcb, uid)
196 (self.locktype, ) = \
197 struct.unpack_from("I", raw[Event.HEADSIZE:])
199 self.typenames = ["__lock", "__unlock", "mtx_lock", "mtx_unlock"]
202 res = Event.__repr__(self)
203 res += "LOCK(%d)" % self.locktype
207 return ["Lock(%s)" % self.typenames[self.locktype]]
210 class SHMLockingEvent(Event):
211 """SHM locking event"""
212 def __init__(self, raw, time=0, utcb=0, uid=None):
213 Event.__init__(self, time, Event.SHMLOCKING_TYPE, utcb, uid)
214 (self.lockid, self.epoch, self.owner, self.evtype) = \
215 struct.unpack_from("IIII", raw[Event.HEADSIZE:])
218 res = Event.__repr__(self)
219 res += "SHM %x, %d, %x" % (self.lockid, self.epoch, self.evtype)
224 st1 = ["down1", "down2", "up1", "up2"][self.evtype - 2]
225 st1 += "(%x)" % self.lockid
227 st2 = " ID %x, EP %x" % (self.utcb, self.epoch)
230 if self.evtype in [2, 5]:
231 if self.owner == 0xffffffff:
232 st3 = "(owner: %x)" % self.owner
234 st3 = "(owner: \033[31;1m%x\033[0m)" % self.owner
237 return ["\033[34;1m==========\033[0m", st1, st2, st3]
239 return [st1, st3, "\033[34m==========\033[0m"]
244 class BarnesEvent(Event):
245 """SPLASH2::Barnes runtime event"""
246 def __init__(self, raw, time=0, utcb=0, uid=None):
247 Event.__init__(self, time, Event.SHMLOCKING_TYPE, utcb, uid)
248 (self.ptr, self.num, self.type) = \
249 struct.unpack_from("III", raw[Event.HEADSIZE:])
252 return "Barnes(%d) ptr %x num %d" % (self.type, self.ptr, self.num)
255 return ["\033[32mbarnes(%d)\033[0m" % self.type,
256 "%x %d\033[0m" % (self.ptr, self.num)]