History

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

Tony Jones committed 7 years ago

Commit c253c721 parent 57e604b1 file · +25 −23Browse files

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

Unified · Split

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