0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 from __future__ import print_function
0012
0013 import struct
0014
0015
0016 EVTYPE_GENERIC = 0
0017 EVTYPE_PEBS = 1
0018 EVTYPE_PEBS_LL = 2
0019 EVTYPE_IBS = 3
0020
0021
0022
0023
0024
0025
0026 def create_event(name, comm, dso, symbol, raw_buf):
0027 if (len(raw_buf) == 144):
0028 event = PebsEvent(name, comm, dso, symbol, raw_buf)
0029 elif (len(raw_buf) == 176):
0030 event = PebsNHM(name, comm, dso, symbol, raw_buf)
0031 else:
0032 event = PerfEvent(name, comm, dso, symbol, raw_buf)
0033
0034 return event
0035
0036 class PerfEvent(object):
0037 event_num = 0
0038 def __init__(self, name, comm, dso, symbol, raw_buf, ev_type=EVTYPE_GENERIC):
0039 self.name = name
0040 self.comm = comm
0041 self.dso = dso
0042 self.symbol = symbol
0043 self.raw_buf = raw_buf
0044 self.ev_type = ev_type
0045 PerfEvent.event_num += 1
0046
0047 def show(self):
0048 print("PMU event: name=%12s, symbol=%24s, comm=%8s, dso=%12s" %
0049 (self.name, self.symbol, self.comm, self.dso))
0050
0051
0052
0053
0054
0055
0056 class PebsEvent(PerfEvent):
0057 pebs_num = 0
0058 def __init__(self, name, comm, dso, symbol, raw_buf, ev_type=EVTYPE_PEBS):
0059 tmp_buf=raw_buf[0:80]
0060 flags, ip, ax, bx, cx, dx, si, di, bp, sp = struct.unpack('QQQQQQQQQQ', tmp_buf)
0061 self.flags = flags
0062 self.ip = ip
0063 self.ax = ax
0064 self.bx = bx
0065 self.cx = cx
0066 self.dx = dx
0067 self.si = si
0068 self.di = di
0069 self.bp = bp
0070 self.sp = sp
0071
0072 PerfEvent.__init__(self, name, comm, dso, symbol, raw_buf, ev_type)
0073 PebsEvent.pebs_num += 1
0074 del tmp_buf
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085 class PebsNHM(PebsEvent):
0086 pebs_nhm_num = 0
0087 def __init__(self, name, comm, dso, symbol, raw_buf, ev_type=EVTYPE_PEBS_LL):
0088 tmp_buf=raw_buf[144:176]
0089 status, dla, dse, lat = struct.unpack('QQQQ', tmp_buf)
0090 self.status = status
0091 self.dla = dla
0092 self.dse = dse
0093 self.lat = lat
0094
0095 PebsEvent.__init__(self, name, comm, dso, symbol, raw_buf, ev_type)
0096 PebsNHM.pebs_nhm_num += 1
0097 del tmp_buf