| .. | .. |
|---|
| 10 | 10 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 11 | 11 | # more details. |
|---|
| 12 | 12 | |
|---|
| 13 | +from __future__ import print_function |
|---|
| 14 | + |
|---|
| 13 | 15 | import os |
|---|
| 14 | 16 | import sys |
|---|
| 15 | 17 | import struct |
|---|
| .. | .. |
|---|
| 22 | 24 | #from Core import * |
|---|
| 23 | 25 | |
|---|
| 24 | 26 | def trace_begin(): |
|---|
| 25 | | - print "Intel PT Power Events and PTWRITE" |
|---|
| 27 | + print("Intel PT Power Events and PTWRITE") |
|---|
| 26 | 28 | |
|---|
| 27 | 29 | def trace_end(): |
|---|
| 28 | | - print "End" |
|---|
| 30 | + print("End") |
|---|
| 29 | 31 | |
|---|
| 30 | 32 | def trace_unhandled(event_name, context, event_fields_dict): |
|---|
| 31 | | - print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]) |
|---|
| 33 | + print(' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])) |
|---|
| 32 | 34 | |
|---|
| 33 | 35 | def print_ptwrite(raw_buf): |
|---|
| 34 | 36 | data = struct.unpack_from("<IQ", raw_buf) |
|---|
| 35 | 37 | flags = data[0] |
|---|
| 36 | 38 | payload = data[1] |
|---|
| 37 | 39 | exact_ip = flags & 1 |
|---|
| 38 | | - print "IP: %u payload: %#x" % (exact_ip, payload), |
|---|
| 40 | + print("IP: %u payload: %#x" % (exact_ip, payload), end=' ') |
|---|
| 39 | 41 | |
|---|
| 40 | 42 | def print_cbr(raw_buf): |
|---|
| 41 | 43 | data = struct.unpack_from("<BBBBII", raw_buf) |
|---|
| 42 | 44 | cbr = data[0] |
|---|
| 43 | 45 | f = (data[4] + 500) / 1000 |
|---|
| 44 | 46 | p = ((cbr * 1000 / data[2]) + 5) / 10 |
|---|
| 45 | | - print "%3u freq: %4u MHz (%3u%%)" % (cbr, f, p), |
|---|
| 47 | + print("%3u freq: %4u MHz (%3u%%)" % (cbr, f, p), end=' ') |
|---|
| 46 | 48 | |
|---|
| 47 | 49 | def print_mwait(raw_buf): |
|---|
| 48 | 50 | data = struct.unpack_from("<IQ", raw_buf) |
|---|
| 49 | 51 | payload = data[1] |
|---|
| 50 | 52 | hints = payload & 0xff |
|---|
| 51 | 53 | extensions = (payload >> 32) & 0x3 |
|---|
| 52 | | - print "hints: %#x extensions: %#x" % (hints, extensions), |
|---|
| 54 | + print("hints: %#x extensions: %#x" % (hints, extensions), end=' ') |
|---|
| 53 | 55 | |
|---|
| 54 | 56 | def print_pwre(raw_buf): |
|---|
| 55 | 57 | data = struct.unpack_from("<IQ", raw_buf) |
|---|
| .. | .. |
|---|
| 57 | 59 | hw = (payload >> 7) & 1 |
|---|
| 58 | 60 | cstate = (payload >> 12) & 0xf |
|---|
| 59 | 61 | subcstate = (payload >> 8) & 0xf |
|---|
| 60 | | - print "hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate), |
|---|
| 62 | + print("hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate), |
|---|
| 63 | + end=' ') |
|---|
| 61 | 64 | |
|---|
| 62 | 65 | def print_exstop(raw_buf): |
|---|
| 63 | 66 | data = struct.unpack_from("<I", raw_buf) |
|---|
| 64 | 67 | flags = data[0] |
|---|
| 65 | 68 | exact_ip = flags & 1 |
|---|
| 66 | | - print "IP: %u" % (exact_ip), |
|---|
| 69 | + print("IP: %u" % (exact_ip), end=' ') |
|---|
| 67 | 70 | |
|---|
| 68 | 71 | def print_pwrx(raw_buf): |
|---|
| 69 | 72 | data = struct.unpack_from("<IQ", raw_buf) |
|---|
| .. | .. |
|---|
| 71 | 74 | deepest_cstate = payload & 0xf |
|---|
| 72 | 75 | last_cstate = (payload >> 4) & 0xf |
|---|
| 73 | 76 | wake_reason = (payload >> 8) & 0xf |
|---|
| 74 | | - print "deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason), |
|---|
| 77 | + print("deepest cstate: %u last cstate: %u wake reason: %#x" % |
|---|
| 78 | + (deepest_cstate, last_cstate, wake_reason), end=' ') |
|---|
| 75 | 79 | |
|---|
| 76 | 80 | def print_common_start(comm, sample, name): |
|---|
| 77 | 81 | ts = sample["time"] |
|---|
| 78 | 82 | cpu = sample["cpu"] |
|---|
| 79 | 83 | pid = sample["pid"] |
|---|
| 80 | 84 | tid = sample["tid"] |
|---|
| 81 | | - print "%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name), |
|---|
| 85 | + print("%16s %5u/%-5u [%03u] %9u.%09u %7s:" % |
|---|
| 86 | + (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name), |
|---|
| 87 | + end=' ') |
|---|
| 82 | 88 | |
|---|
| 83 | 89 | def print_common_ip(sample, symbol, dso): |
|---|
| 84 | 90 | ip = sample["ip"] |
|---|
| 85 | | - print "%16x %s (%s)" % (ip, symbol, dso) |
|---|
| 91 | + print("%16x %s (%s)" % (ip, symbol, dso)) |
|---|
| 86 | 92 | |
|---|
| 87 | 93 | def process_event(param_dict): |
|---|
| 88 | | - event_attr = param_dict["attr"] |
|---|
| 89 | | - sample = param_dict["sample"] |
|---|
| 90 | | - raw_buf = param_dict["raw_buf"] |
|---|
| 91 | | - comm = param_dict["comm"] |
|---|
| 92 | | - name = param_dict["ev_name"] |
|---|
| 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"] |
|---|
| 93 | 99 | |
|---|
| 94 | | - # Symbol and dso info are not always resolved |
|---|
| 95 | | - if (param_dict.has_key("dso")): |
|---|
| 96 | | - dso = param_dict["dso"] |
|---|
| 97 | | - else: |
|---|
| 98 | | - dso = "[unknown]" |
|---|
| 100 | + # Symbol and dso info are not always resolved |
|---|
| 101 | + if "dso" in param_dict: |
|---|
| 102 | + dso = param_dict["dso"] |
|---|
| 103 | + else: |
|---|
| 104 | + dso = "[unknown]" |
|---|
| 99 | 105 | |
|---|
| 100 | | - if (param_dict.has_key("symbol")): |
|---|
| 101 | | - symbol = param_dict["symbol"] |
|---|
| 102 | | - else: |
|---|
| 103 | | - symbol = "[unknown]" |
|---|
| 106 | + if "symbol" in param_dict: |
|---|
| 107 | + symbol = param_dict["symbol"] |
|---|
| 108 | + else: |
|---|
| 109 | + symbol = "[unknown]" |
|---|
| 104 | 110 | |
|---|
| 105 | 111 | if name == "ptwrite": |
|---|
| 106 | 112 | print_common_start(comm, sample, name) |
|---|