diff options
author | Tony Jones <tonyj@suse.de> | 2019-03-05 11:19:02 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-03-06 16:12:33 -0500 |
commit | fdf2460c297f1bb2f3bd20b3b52903b267af9050 (patch) | |
tree | eaa985691694948a888daec730ec0b1eb5ac6234 /tools | |
parent | c253c72e9d6723c8b078beb362f050059ef5de39 (diff) |
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
Signed-off-by: Tony Jones <tonyj@suse.de>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Link: http://lkml.kernel.org/r/fd26acf9-0c0f-717f-9664-a3c33043ce19@suse.de
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/scripts/python/intel-pt-events.py | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/tools/perf/scripts/python/intel-pt-events.py b/tools/perf/scripts/python/intel-pt-events.py index 2177722f509e..a73847c8f548 100644 --- a/tools/perf/scripts/python/intel-pt-events.py +++ b/tools/perf/scripts/python/intel-pt-events.py | |||
@@ -10,6 +10,8 @@ | |||
10 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | 10 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
11 | # more details. | 11 | # more details. |
12 | 12 | ||
13 | from __future__ import print_function | ||
14 | |||
13 | import os | 15 | import os |
14 | import sys | 16 | import sys |
15 | import struct | 17 | import struct |
@@ -22,34 +24,34 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | |||
22 | #from Core import * | 24 | #from Core import * |
23 | 25 | ||
24 | def trace_begin(): | 26 | def trace_begin(): |
25 | print "Intel PT Power Events and PTWRITE" | 27 | print("Intel PT Power Events and PTWRITE") |
26 | 28 | ||
27 | def trace_end(): | 29 | def trace_end(): |
28 | print "End" | 30 | print("End") |
29 | 31 | ||
30 | def trace_unhandled(event_name, context, event_fields_dict): | 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 | def print_ptwrite(raw_buf): | 35 | def print_ptwrite(raw_buf): |
34 | data = struct.unpack_from("<IQ", raw_buf) | 36 | data = struct.unpack_from("<IQ", raw_buf) |
35 | flags = data[0] | 37 | flags = data[0] |
36 | payload = data[1] | 38 | payload = data[1] |
37 | exact_ip = flags & 1 | 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 | def print_cbr(raw_buf): | 42 | def print_cbr(raw_buf): |
41 | data = struct.unpack_from("<BBBBII", raw_buf) | 43 | data = struct.unpack_from("<BBBBII", raw_buf) |
42 | cbr = data[0] | 44 | cbr = data[0] |
43 | f = (data[4] + 500) / 1000 | 45 | f = (data[4] + 500) / 1000 |
44 | p = ((cbr * 1000 / data[2]) + 5) / 10 | 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 | def print_mwait(raw_buf): | 49 | def print_mwait(raw_buf): |
48 | data = struct.unpack_from("<IQ", raw_buf) | 50 | data = struct.unpack_from("<IQ", raw_buf) |
49 | payload = data[1] | 51 | payload = data[1] |
50 | hints = payload & 0xff | 52 | hints = payload & 0xff |
51 | extensions = (payload >> 32) & 0x3 | 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 | def print_pwre(raw_buf): | 56 | def print_pwre(raw_buf): |
55 | data = struct.unpack_from("<IQ", raw_buf) | 57 | data = struct.unpack_from("<IQ", raw_buf) |
@@ -57,13 +59,14 @@ def print_pwre(raw_buf): | |||
57 | hw = (payload >> 7) & 1 | 59 | hw = (payload >> 7) & 1 |
58 | cstate = (payload >> 12) & 0xf | 60 | cstate = (payload >> 12) & 0xf |
59 | subcstate = (payload >> 8) & 0xf | 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 | def print_exstop(raw_buf): | 65 | def print_exstop(raw_buf): |
63 | data = struct.unpack_from("<I", raw_buf) | 66 | data = struct.unpack_from("<I", raw_buf) |
64 | flags = data[0] | 67 | flags = data[0] |
65 | exact_ip = flags & 1 | 68 | exact_ip = flags & 1 |
66 | print "IP: %u" % (exact_ip), | 69 | print("IP: %u" % (exact_ip), end=' ') |
67 | 70 | ||
68 | def print_pwrx(raw_buf): | 71 | def print_pwrx(raw_buf): |
69 | data = struct.unpack_from("<IQ", raw_buf) | 72 | data = struct.unpack_from("<IQ", raw_buf) |
@@ -71,18 +74,21 @@ def print_pwrx(raw_buf): | |||
71 | deepest_cstate = payload & 0xf | 74 | deepest_cstate = payload & 0xf |
72 | last_cstate = (payload >> 4) & 0xf | 75 | last_cstate = (payload >> 4) & 0xf |
73 | wake_reason = (payload >> 8) & 0xf | 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 | def print_common_start(comm, sample, name): | 80 | def print_common_start(comm, sample, name): |
77 | ts = sample["time"] | 81 | ts = sample["time"] |
78 | cpu = sample["cpu"] | 82 | cpu = sample["cpu"] |
79 | pid = sample["pid"] | 83 | pid = sample["pid"] |
80 | tid = sample["tid"] | 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 | def print_common_ip(sample, symbol, dso): | 89 | def print_common_ip(sample, symbol, dso): |
84 | ip = sample["ip"] | 90 | ip = sample["ip"] |
85 | print "%16x %s (%s)" % (ip, symbol, dso) | 91 | print("%16x %s (%s)" % (ip, symbol, dso)) |
86 | 92 | ||
87 | def process_event(param_dict): | 93 | def process_event(param_dict): |
88 | event_attr = param_dict["attr"] | 94 | event_attr = param_dict["attr"] |
@@ -92,12 +98,12 @@ def process_event(param_dict): | |||
92 | name = param_dict["ev_name"] | 98 | name = param_dict["ev_name"] |
93 | 99 | ||
94 | # Symbol and dso info are not always resolved | 100 | # Symbol and dso info are not always resolved |
95 | if (param_dict.has_key("dso")): | 101 | if "dso" in param_dict: |
96 | dso = param_dict["dso"] | 102 | dso = param_dict["dso"] |
97 | else: | 103 | else: |
98 | dso = "[unknown]" | 104 | dso = "[unknown]" |
99 | 105 | ||
100 | if (param_dict.has_key("symbol")): | 106 | if "symbol" in param_dict: |
101 | symbol = param_dict["symbol"] | 107 | symbol = param_dict["symbol"] |
102 | else: | 108 | else: |
103 | symbol = "[unknown]" | 109 | symbol = "[unknown]" |