hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/tools/perf/scripts/python/intel-pt-events.py
....@@ -10,6 +10,8 @@
1010 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1111 # more details.
1212
13
+from __future__ import print_function
14
+
1315 import os
1416 import sys
1517 import struct
....@@ -22,34 +24,34 @@
2224 #from Core import *
2325
2426 def trace_begin():
25
- print "Intel PT Power Events and PTWRITE"
27
+ print("Intel PT Power Events and PTWRITE")
2628
2729 def trace_end():
28
- print "End"
30
+ print("End")
2931
3032 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())]))
3234
3335 def print_ptwrite(raw_buf):
3436 data = struct.unpack_from("<IQ", raw_buf)
3537 flags = data[0]
3638 payload = data[1]
3739 exact_ip = flags & 1
38
- print "IP: %u payload: %#x" % (exact_ip, payload),
40
+ print("IP: %u payload: %#x" % (exact_ip, payload), end=' ')
3941
4042 def print_cbr(raw_buf):
4143 data = struct.unpack_from("<BBBBII", raw_buf)
4244 cbr = data[0]
4345 f = (data[4] + 500) / 1000
4446 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=' ')
4648
4749 def print_mwait(raw_buf):
4850 data = struct.unpack_from("<IQ", raw_buf)
4951 payload = data[1]
5052 hints = payload & 0xff
5153 extensions = (payload >> 32) & 0x3
52
- print "hints: %#x extensions: %#x" % (hints, extensions),
54
+ print("hints: %#x extensions: %#x" % (hints, extensions), end=' ')
5355
5456 def print_pwre(raw_buf):
5557 data = struct.unpack_from("<IQ", raw_buf)
....@@ -57,13 +59,14 @@
5759 hw = (payload >> 7) & 1
5860 cstate = (payload >> 12) & 0xf
5961 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=' ')
6164
6265 def print_exstop(raw_buf):
6366 data = struct.unpack_from("<I", raw_buf)
6467 flags = data[0]
6568 exact_ip = flags & 1
66
- print "IP: %u" % (exact_ip),
69
+ print("IP: %u" % (exact_ip), end=' ')
6770
6871 def print_pwrx(raw_buf):
6972 data = struct.unpack_from("<IQ", raw_buf)
....@@ -71,36 +74,39 @@
7174 deepest_cstate = payload & 0xf
7275 last_cstate = (payload >> 4) & 0xf
7376 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=' ')
7579
7680 def print_common_start(comm, sample, name):
7781 ts = sample["time"]
7882 cpu = sample["cpu"]
7983 pid = sample["pid"]
8084 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=' ')
8288
8389 def print_common_ip(sample, symbol, dso):
8490 ip = sample["ip"]
85
- print "%16x %s (%s)" % (ip, symbol, dso)
91
+ print("%16x %s (%s)" % (ip, symbol, dso))
8692
8793 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"]
9399
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]"
99105
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]"
104110
105111 if name == "ptwrite":
106112 print_common_start(comm, sample, name)