History

perf script python: Add Python3 support to intel-pt-events.py

Support both Python2 and Python3 in the intel-pt-events.py script There may be differences in the ordering of output lines due to differences in dictionary ordering etc. However the format within lines should be unchanged. The use of 'from __future__' implies the minimum supported Python2 version is now v2.6

Tony Jones committed 7 years ago

Commit fdf24601 parent c253c721 file · +19 −13Browse files

Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all

Unified · Split

tools/perf/scripts/python/intel-pt-events.py+19−13
@@ -10,6 +10,8 @@ · 9 unmodified lines
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 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \ · 6 unmodified lines
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 @@ def print_pwre(raw_buf): · 1 unmodified line
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,18 +74,21 @@ def print_pwrx(raw_buf): · 1 unmodified line
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):
8894 event_attr = param_dict["attr"]
@@ -92,12 +98,12 @@ def process_event(param_dict): · 3 unmodified lines
9298 name = param_dict["ev_name"]
9399
94100 # Symbol and dso info are not always resolved
95− if (param_dict.has_key("dso")):
101+ if "dso" in param_dict:
96102 dso = param_dict["dso"]
97103 else:
98104 dso = "[unknown]"
99105
100− if (param_dict.has_key("symbol")):
106+ if "symbol" in param_dict:
101107 symbol = param_dict["symbol"]
102108 else:
103109 symbol = "[unknown]"

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t