| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 |
|
| 13 | from __future__ import print_function
|
| 14 |
|
| 15 | import os
|
| 16 | import sys
|
| 17 | import struct
|
| 18 |
|
| 19 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \
|
| 20 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
|
| 21 |
|
| 22 | |
| 23 | |
| 24 | |
| 25 |
|
| 26 | def trace_begin():
|
| 27 | print("Intel PT Power Events and PTWRITE")
|
| 28 |
|
| 29 | def trace_end():
|
| 30 | print("End")
|
| 31 |
|
| 32 | def trace_unhandled(event_name, context, event_fields_dict):
|
| 33 | print(' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]))
|
| 34 |
|
| 35 | def print_ptwrite(raw_buf):
|
| 36 | data = struct.unpack_from("<IQ", raw_buf)
|
| 37 | flags = data[0]
|
| 38 | payload = data[1]
|
| 39 | exact_ip = flags & 1
|
| 40 | print("IP: %u payload: %#x" % (exact_ip, payload), end=' ')
|
| 41 |
|
| 42 | def print_cbr(raw_buf):
|
| 43 | data = struct.unpack_from("<BBBBII", raw_buf)
|
| 44 | cbr = data[0]
|
| 45 | f = (data[4] + 500) / 1000
|
| 46 | p = ((cbr * 1000 / data[2]) + 5) / 10
|
| 47 | print("%3u freq: %4u MHz (%3u%%)" % (cbr, f, p), end=' ')
|
| 48 |
|
| 49 | def print_mwait(raw_buf):
|
| 50 | data = struct.unpack_from("<IQ", raw_buf)
|
| 51 | payload = data[1]
|
| 52 | hints = payload & 0xff
|
| 53 | extensions = (payload >> 32) & 0x3
|
| 54 | print("hints: %#x extensions: %#x" % (hints, extensions), end=' ')
|
| 55 |
|
| 56 | def print_pwre(raw_buf):
|
| 57 | data = struct.unpack_from("<IQ", raw_buf)
|
| 58 | payload = data[1]
|
| 59 | hw = (payload >> 7) & 1
|
| 60 | cstate = (payload >> 12) & 0xf
|
| 61 | subcstate = (payload >> 8) & 0xf
|
| 62 | print("hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate),
|
| 63 | end=' ')
|
| 64 |
|
| 65 | def print_exstop(raw_buf):
|
| 66 | data = struct.unpack_from("<I", raw_buf)
|
| 67 | flags = data[0]
|
| 68 | exact_ip = flags & 1
|
| 69 | print("IP: %u" % (exact_ip), end=' ')
|
| 70 |
|
| 71 | def print_pwrx(raw_buf):
|
| 72 | data = struct.unpack_from("<IQ", raw_buf)
|
| 73 | payload = data[1]
|
| 74 | deepest_cstate = payload & 0xf
|
| 75 | last_cstate = (payload >> 4) & 0xf
|
| 76 | wake_reason = (payload >> 8) & 0xf
|
| 77 | print("deepest cstate: %u last cstate: %u wake reason: %#x" %
|
| 78 | (deepest_cstate, last_cstate, wake_reason), end=' ')
|
| 79 |
|
| 80 | def print_common_start(comm, sample, name):
|
| 81 | ts = sample["time"]
|
| 82 | cpu = sample["cpu"]
|
| 83 | pid = sample["pid"]
|
| 84 | tid = sample["tid"]
|
| 85 | print("%16s %5u/%-5u [%03u] %9u.%09u %7s:" %
|
| 86 | (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name),
|
| 87 | end=' ')
|
| 88 |
|
| 89 | def print_common_ip(sample, symbol, dso):
|
| 90 | ip = sample["ip"]
|
| 91 | print("%16x %s (%s)" % (ip, symbol, dso))
|
| 92 |
|
| 93 | def process_event(param_dict):
|
| 94 | event_attr = param_dict["attr"]
|
| 95 | sample = param_dict["sample"]
|
| 96 | raw_buf = param_dict["raw_buf"]
|
| 97 | comm = param_dict["comm"]
|
| 98 | name = param_dict["ev_name"]
|
| 99 |
|
| 100 | |
| 101 | if "dso" in param_dict:
|
| 102 | dso = param_dict["dso"]
|
| 103 | else:
|
| 104 | dso = "[unknown]"
|
| 105 |
|
| 106 | if "symbol" in param_dict:
|
| 107 | symbol = param_dict["symbol"]
|
| 108 | else:
|
| 109 | symbol = "[unknown]"
|
| 110 |
|
| 111 | if name == "ptwrite":
|
| 112 | print_common_start(comm, sample, name)
|
| 113 | print_ptwrite(raw_buf)
|
| 114 | print_common_ip(sample, symbol, dso)
|
| 115 | elif name == "cbr":
|
| 116 | print_common_start(comm, sample, name)
|
| 117 | print_cbr(raw_buf)
|
| 118 | print_common_ip(sample, symbol, dso)
|
| 119 | elif name == "mwait":
|
| 120 | print_common_start(comm, sample, name)
|
| 121 | print_mwait(raw_buf)
|
| 122 | print_common_ip(sample, symbol, dso)
|
| 123 | elif name == "pwre":
|
| 124 | print_common_start(comm, sample, name)
|
| 125 | print_pwre(raw_buf)
|
| 126 | print_common_ip(sample, symbol, dso)
|
| 127 | elif name == "exstop":
|
| 128 | print_common_start(comm, sample, name)
|
| 129 | print_exstop(raw_buf)
|
| 130 | print_common_ip(sample, symbol, dso)
|
| 131 | elif name == "pwrx":
|
| 132 | print_common_start(comm, sample, name)
|
| 133 | print_pwrx(raw_buf)
|
| 134 | print_common_ip(sample, symbol, dso)
|