hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/tools/perf/scripts/python/event_analyzing_sample.py
....@@ -15,6 +15,8 @@
1515 # for a x86 HW PMU event: PEBS with load latency data.
1616 #
1717
18
+from __future__ import print_function
19
+
1820 import os
1921 import sys
2022 import math
....@@ -37,7 +39,7 @@
3739 con.isolation_level = None
3840
3941 def trace_begin():
40
- print "In trace_begin:\n"
42
+ print("In trace_begin:\n")
4143
4244 #
4345 # Will create several tables at the start, pebs_ll is for PEBS data with
....@@ -76,12 +78,12 @@
7678 name = param_dict["ev_name"]
7779
7880 # Symbol and dso info are not always resolved
79
- if (param_dict.has_key("dso")):
81
+ if ("dso" in param_dict):
8082 dso = param_dict["dso"]
8183 else:
8284 dso = "Unknown_dso"
8385
84
- if (param_dict.has_key("symbol")):
86
+ if ("symbol" in param_dict):
8587 symbol = param_dict["symbol"]
8688 else:
8789 symbol = "Unknown_symbol"
....@@ -102,7 +104,7 @@
102104 event.ip, event.status, event.dse, event.dla, event.lat))
103105
104106 def trace_end():
105
- print "In trace_end:\n"
107
+ print("In trace_end:\n")
106108 # We show the basic info for the 2 type of event classes
107109 show_general_events()
108110 show_pebs_ll()
....@@ -123,29 +125,29 @@
123125 # Check the total record number in the table
124126 count = con.execute("select count(*) from gen_events")
125127 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])
127129 if t[0] == 0:
128130 return
129131
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")
131133
132134 # Group by thread
133135 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))
135137 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])))
137139
138140 # 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))
140142 symbolq = con.execute("select symbol, count(symbol) from gen_events group by symbol order by -count(symbol)")
141143 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])))
143145
144146 # 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))
146148 dsoq = con.execute("select dso, count(dso) from gen_events group by dso order by -count(dso)")
147149 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])))
149151
150152 #
151153 # This function just shows the basic info, and we could do more with the
....@@ -156,35 +158,35 @@
156158
157159 count = con.execute("select count(*) from pebs_ll")
158160 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])
160162 if t[0] == 0:
161163 return
162164
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")
164166
165167 # Group by thread
166168 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))
168170 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])))
170172
171173 # 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))
173175 symbolq = con.execute("select symbol, count(symbol) from pebs_ll group by symbol order by -count(symbol)")
174176 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])))
176178
177179 # Group by dse
178180 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))
180182 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])))
182184
183185 # Group by latency
184186 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))
186188 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])))
188190
189191 def 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())]))