~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 # EventClass.py
  2 # SPDX-License-Identifier: GPL-2.0
  3 #
  4 # This is a library defining some events types classes, which could
  5 # be used by other scripts to analyzing the perf samples.
  6 #
  7 # Currently there are just a few classes defined for examples,
  8 # PerfEvent is the base class for all perf event sample, PebsEvent
  9 # is a HW base Intel x86 PEBS event, and user could add more SW/HW
 10 # event classes based on requirements.
 11 from __future__ import print_function
 12 
 13 import struct
 14 
 15 # Event types, user could add more here
 16 EVTYPE_GENERIC  = 0
 17 EVTYPE_PEBS     = 1     # Basic PEBS event
 18 EVTYPE_PEBS_LL  = 2     # PEBS event with load latency info
 19 EVTYPE_IBS      = 3
 20 
 21 #
 22 # Currently we don't have good way to tell the event type, but by
 23 # the size of raw buffer, raw PEBS event with load latency data's
 24 # size is 176 bytes, while the pure PEBS event's size is 144 bytes.
 25 #
 26 def create_event(name, comm, dso, symbol, raw_buf):
 27         if (len(raw_buf) == 144):
 28                 event = PebsEvent(name, comm, dso, symbol, raw_buf)
 29         elif (len(raw_buf) == 176):
 30                 event = PebsNHM(name, comm, dso, symbol, raw_buf)
 31         else:
 32                 event = PerfEvent(name, comm, dso, symbol, raw_buf)
 33 
 34         return event
 35 
 36 class PerfEvent(object):
 37         event_num = 0
 38         def __init__(self, name, comm, dso, symbol, raw_buf, ev_type=EVTYPE_GENERIC):
 39                 self.name       = name
 40                 self.comm       = comm
 41                 self.dso        = dso
 42                 self.symbol     = symbol
 43                 self.raw_buf    = raw_buf
 44                 self.ev_type    = ev_type
 45                 PerfEvent.event_num += 1
 46 
 47         def show(self):
 48                 print("PMU event: name=%12s, symbol=%24s, comm=%8s, dso=%12s" %
 49                       (self.name, self.symbol, self.comm, self.dso))
 50 
 51 #
 52 # Basic Intel PEBS (Precise Event-based Sampling) event, whose raw buffer
 53 # contains the context info when that event happened: the EFLAGS and
 54 # linear IP info, as well as all the registers.
 55 #
 56 class PebsEvent(PerfEvent):
 57         pebs_num = 0
 58         def __init__(self, name, comm, dso, symbol, raw_buf, ev_type=EVTYPE_PEBS):
 59                 tmp_buf=raw_buf[0:80]
 60                 flags, ip, ax, bx, cx, dx, si, di, bp, sp = struct.unpack('QQQQQQQQQQ', tmp_buf)
 61                 self.flags = flags
 62                 self.ip    = ip
 63                 self.ax    = ax
 64                 self.bx    = bx
 65                 self.cx    = cx
 66                 self.dx    = dx
 67                 self.si    = si
 68                 self.di    = di
 69                 self.bp    = bp
 70                 self.sp    = sp
 71 
 72                 PerfEvent.__init__(self, name, comm, dso, symbol, raw_buf, ev_type)
 73                 PebsEvent.pebs_num += 1
 74                 del tmp_buf
 75 
 76 #
 77 # Intel Nehalem and Westmere support PEBS plus Load Latency info which lie
 78 # in the four 64 bit words write after the PEBS data:
 79 #       Status: records the IA32_PERF_GLOBAL_STATUS register value
 80 #       DLA:    Data Linear Address (EIP)
 81 #       DSE:    Data Source Encoding, where the latency happens, hit or miss
 82 #               in L1/L2/L3 or IO operations
 83 #       LAT:    the actual latency in cycles
 84 #
 85 class PebsNHM(PebsEvent):
 86         pebs_nhm_num = 0
 87         def __init__(self, name, comm, dso, symbol, raw_buf, ev_type=EVTYPE_PEBS_LL):
 88                 tmp_buf=raw_buf[144:176]
 89                 status, dla, dse, lat = struct.unpack('QQQQ', tmp_buf)
 90                 self.status = status
 91                 self.dla = dla
 92                 self.dse = dse
 93                 self.lat = lat
 94 
 95                 PebsEvent.__init__(self, name, comm, dso, symbol, raw_buf, ev_type)
 96                 PebsNHM.pebs_nhm_num += 1
 97                 del tmp_buf

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php