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
4#4#
5# Hypervisor call statisics5# Hypervisor call statisics
6 6
7from __future__ import print_function
8
7import os9import os
8import sys10import sys
9 11
@@ -149,7 +151,7 @@ hcall_table = { · 139 unmodified lines
149}151}
150 152
151def hcall_table_lookup(opcode):153def hcall_table_lookup(opcode):
152 if (hcall_table.has_key(opcode)):154 if (opcode in hcall_table):
153 return hcall_table[opcode]155 return hcall_table[opcode]
154 else:156 else:
155 return opcode157 return opcode
@@ -157,8 +159,8 @@ def hcall_table_lookup(opcode): · 1 unmodified line
157print_ptrn = '%-28s%10s%10s%10s%10s'159print_ptrn = '%-28s%10s%10s%10s%10s'
158 160
159def trace_end():161def trace_end():
160 print print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)')162 print(print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)'))
161 print '-' * 68163 print('-' * 68)
162 for opcode in output:164 for opcode in output:
163 h_name = hcall_table_lookup(opcode)165 h_name = hcall_table_lookup(opcode)
164 time = output[opcode]['time']166 time = output[opcode]['time']
@@ -166,14 +168,14 @@ def trace_end(): · 1 unmodified line
166 min_t = output[opcode]['min']168 min_t = output[opcode]['min']
167 max_t = output[opcode]['max']169 max_t = output[opcode]['max']
168 170
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))
170 172
171def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain,173def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain,
172 opcode, retval):174 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]):
174 diff = nsecs(sec, nsec) - d_enter[cpu][opcode]176 diff = nsecs(sec, nsec) - d_enter[cpu][opcode]
175 177
176 if (output.has_key(opcode)):178 if (opcode in output):
177 output[opcode]['time'] += diff179 output[opcode]['time'] += diff
178 output[opcode]['cnt'] += 1180 output[opcode]['cnt'] += 1
179 if (output[opcode]['min'] > diff):181 if (output[opcode]['min'] > diff):
@@ -190,11 +192,11 @@ def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain, · 10 unmodified lines
190 192
191 del d_enter[cpu][opcode]193 del d_enter[cpu][opcode]
192# else:194# else:
193# print "Can't find matching hcall_enter event. Ignoring sample"195# print("Can't find matching hcall_enter event. Ignoring sample")
194 196
195def powerpc__hcall_entry(event_name, context, cpu, sec, nsec, pid, comm,197def powerpc__hcall_entry(event_name, context, cpu, sec, nsec, pid, comm,
196 callchain, opcode):198 callchain, opcode):
197 if (d_enter.has_key(cpu)):199 if (cpu in d_enter):
198 d_enter[cpu][opcode] = nsecs(sec, nsec)200 d_enter[cpu][opcode] = nsecs(sec, nsec)
199 else:201 else:
200 d_enter[cpu] = {opcode: nsecs(sec, nsec)}202 d_enter[cpu] = {opcode: nsecs(sec, nsec)}