History

perf script python: Add Python3 support to powerpc-hcalls.py

Support both Python2 and Python3 in the powerpc-hcalls.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 118af5b1 parent 8c42b961 file · +10 −8Browse files

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

Unified · Split

tools/perf/scripts/python/powerpc-hcalls.py+10−8
@@ -4,6 +4,8 @@ · 3 unmodified lines
44 #
55 # Hypervisor call statisics
66
7+from __future__ import print_function
8+
79 import os
810 import sys
911
@@ -149,7 +151,7 @@ hcall_table = { · 139 unmodified lines
149151 }
150152
151153 def hcall_table_lookup(opcode):
152− if (hcall_table.has_key(opcode)):
154+ if (opcode in hcall_table):
153155 return hcall_table[opcode]
154156 else:
155157 return opcode
@@ -157,8 +159,8 @@ def hcall_table_lookup(opcode): · 1 unmodified line
157159 print_ptrn = '%-28s%10s%10s%10s%10s'
158160
159161 def trace_end():
160− print print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)')
161− print '-' * 68
162+ print(print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)'))
163+ print('-' * 68)
162164 for opcode in output:
163165 h_name = hcall_table_lookup(opcode)
164166 time = output[opcode]['time']
@@ -166,14 +168,14 @@ def trace_end(): · 1 unmodified line
166168 min_t = output[opcode]['min']
167169 max_t = output[opcode]['max']
168170
169− print print_ptrn % (h_name, cnt, min_t, max_t, time/cnt)
171+ print(print_ptrn % (h_name, cnt, min_t, max_t, time//cnt))
170172
171173 def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain,
172174 opcode, retval):
173− if (d_enter.has_key(cpu) and d_enter[cpu].has_key(opcode)):
175+ if (cpu in d_enter and opcode in d_enter[cpu]):
174176 diff = nsecs(sec, nsec) - d_enter[cpu][opcode]
175177
176− if (output.has_key(opcode)):
178+ if (opcode in output):
177179 output[opcode]['time'] += diff
178180 output[opcode]['cnt'] += 1
179181 if (output[opcode]['min'] > diff):
@@ -190,11 +192,11 @@ def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain, · 10 unmodified lines
190192
191193 del d_enter[cpu][opcode]
192194 # else:
193−# print "Can't find matching hcall_enter event. Ignoring sample"
195+# print("Can't find matching hcall_enter event. Ignoring sample")
194196
195197 def powerpc__hcall_entry(event_name, context, cpu, sec, nsec, pid, comm,
196198 callchain, opcode):
197− if (d_enter.has_key(cpu)):
199+ if (cpu in d_enter):
198200 d_enter[cpu][opcode] = nsecs(sec, nsec)
199201 else:
200202 d_enter[cpu] = {opcode: nsecs(sec, nsec)}