Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

Signed-off-by: Tony Jones <tonyj@suse.de>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Link: http://lkml.kernel.org/r/20190222230619.17887-10-tonyj@suse.de
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Tony Jones and committed by
Arnaldo Carvalho de Melo
118af5bf 8c42b960

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