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 event_analyzing_sample.py

Support both Python2 and Python3 in the event_analyzing_sample.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: Feng Tang <feng.tang@intel.com>
Link: http://lkml.kernel.org/r/20190302011903.2416-5-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
c253c72e 57e604b1

+25 -23
+25 -23
tools/perf/scripts/python/event_analyzing_sample.py
··· 15 15 # for a x86 HW PMU event: PEBS with load latency data. 16 16 # 17 17 18 + from __future__ import print_function 19 + 18 20 import os 19 21 import sys 20 22 import math ··· 39 37 con.isolation_level = None 40 38 41 39 def trace_begin(): 42 - print "In trace_begin:\n" 40 + print("In trace_begin:\n") 43 41 44 42 # 45 43 # Will create several tables at the start, pebs_ll is for PEBS data with ··· 78 76 name = param_dict["ev_name"] 79 77 80 78 # Symbol and dso info are not always resolved 81 - if (param_dict.has_key("dso")): 79 + if ("dso" in param_dict): 82 80 dso = param_dict["dso"] 83 81 else: 84 82 dso = "Unknown_dso" 85 83 86 - if (param_dict.has_key("symbol")): 84 + if ("symbol" in param_dict): 87 85 symbol = param_dict["symbol"] 88 86 else: 89 87 symbol = "Unknown_symbol" ··· 104 102 event.ip, event.status, event.dse, event.dla, event.lat)) 105 103 106 104 def trace_end(): 107 - print "In trace_end:\n" 105 + print("In trace_end:\n") 108 106 # We show the basic info for the 2 type of event classes 109 107 show_general_events() 110 108 show_pebs_ll() ··· 125 123 # Check the total record number in the table 126 124 count = con.execute("select count(*) from gen_events") 127 125 for t in count: 128 - print "There is %d records in gen_events table" % t[0] 126 + print("There is %d records in gen_events table" % t[0]) 129 127 if t[0] == 0: 130 128 return 131 129 132 - print "Statistics about the general events grouped by thread/symbol/dso: \n" 130 + print("Statistics about the general events grouped by thread/symbol/dso: \n") 133 131 134 132 # Group by thread 135 133 commq = con.execute("select comm, count(comm) from gen_events group by comm order by -count(comm)") 136 - print "\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42) 134 + print("\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42)) 137 135 for row in commq: 138 - print "%16s %8d %s" % (row[0], row[1], num2sym(row[1])) 136 + print("%16s %8d %s" % (row[0], row[1], num2sym(row[1]))) 139 137 140 138 # Group by symbol 141 - print "\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58) 139 + print("\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58)) 142 140 symbolq = con.execute("select symbol, count(symbol) from gen_events group by symbol order by -count(symbol)") 143 141 for row in symbolq: 144 - print "%32s %8d %s" % (row[0], row[1], num2sym(row[1])) 142 + print("%32s %8d %s" % (row[0], row[1], num2sym(row[1]))) 145 143 146 144 # Group by dso 147 - print "\n%40s %8s %16s\n%s" % ("dso", "number", "histogram", "="*74) 145 + print("\n%40s %8s %16s\n%s" % ("dso", "number", "histogram", "="*74)) 148 146 dsoq = con.execute("select dso, count(dso) from gen_events group by dso order by -count(dso)") 149 147 for row in dsoq: 150 - print "%40s %8d %s" % (row[0], row[1], num2sym(row[1])) 148 + print("%40s %8d %s" % (row[0], row[1], num2sym(row[1]))) 151 149 152 150 # 153 151 # This function just shows the basic info, and we could do more with the ··· 158 156 159 157 count = con.execute("select count(*) from pebs_ll") 160 158 for t in count: 161 - print "There is %d records in pebs_ll table" % t[0] 159 + print("There is %d records in pebs_ll table" % t[0]) 162 160 if t[0] == 0: 163 161 return 164 162 165 - print "Statistics about the PEBS Load Latency events grouped by thread/symbol/dse/latency: \n" 163 + print("Statistics about the PEBS Load Latency events grouped by thread/symbol/dse/latency: \n") 166 164 167 165 # Group by thread 168 166 commq = con.execute("select comm, count(comm) from pebs_ll group by comm order by -count(comm)") 169 - print "\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42) 167 + print("\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42)) 170 168 for row in commq: 171 - print "%16s %8d %s" % (row[0], row[1], num2sym(row[1])) 169 + print("%16s %8d %s" % (row[0], row[1], num2sym(row[1]))) 172 170 173 171 # Group by symbol 174 - print "\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58) 172 + print("\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58)) 175 173 symbolq = con.execute("select symbol, count(symbol) from pebs_ll group by symbol order by -count(symbol)") 176 174 for row in symbolq: 177 - print "%32s %8d %s" % (row[0], row[1], num2sym(row[1])) 175 + print("%32s %8d %s" % (row[0], row[1], num2sym(row[1]))) 178 176 179 177 # Group by dse 180 178 dseq = con.execute("select dse, count(dse) from pebs_ll group by dse order by -count(dse)") 181 - print "\n%32s %8s %16s\n%s" % ("dse", "number", "histogram", "="*58) 179 + print("\n%32s %8s %16s\n%s" % ("dse", "number", "histogram", "="*58)) 182 180 for row in dseq: 183 - print "%32s %8d %s" % (row[0], row[1], num2sym(row[1])) 181 + print("%32s %8d %s" % (row[0], row[1], num2sym(row[1]))) 184 182 185 183 # Group by latency 186 184 latq = con.execute("select lat, count(lat) from pebs_ll group by lat order by lat") 187 - print "\n%32s %8s %16s\n%s" % ("latency", "number", "histogram", "="*58) 185 + print("\n%32s %8s %16s\n%s" % ("latency", "number", "histogram", "="*58)) 188 186 for row in latq: 189 - print "%32s %8d %s" % (row[0], row[1], num2sym(row[1])) 187 + print("%32s %8d %s" % (row[0], row[1], num2sym(row[1]))) 190 188 191 189 def trace_unhandled(event_name, context, event_fields_dict): 192 - print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]) 190 + print (' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]))