o3-pipeview.py (9252:f350fac86d0f) o3-pipeview.py (9527:68154bc0e0ea)
1#! /usr/bin/env python
2
3# Copyright (c) 2011 ARM Limited
4# All rights reserved
5#
6# The license below extends only to copyright in the software and shall
7# not be construed as granting a license to any other intellectual
8# property including but not limited to intellectual property relating

--- 50 unchanged lines hidden (view full) ---

59 'sn_stop':0, # The last instruction seq. number to be printed.
60 'tick_start':0, # The first tick to be printed
61 'tick_stop':0, # The last tick to be printed
62 'tick_drift':2000, # Used to calculate the start and the end of main
63 # loop. We assume here that the instructions are not
64 # out of order for more then 2000 CPU ticks,
65 # otherwise the print may not start/stop
66 # at the time specified by tick_start/stop.
1#! /usr/bin/env python
2
3# Copyright (c) 2011 ARM Limited
4# All rights reserved
5#
6# The license below extends only to copyright in the software and shall
7# not be construed as granting a license to any other intellectual
8# property including but not limited to intellectual property relating

--- 50 unchanged lines hidden (view full) ---

59 'sn_stop':0, # The last instruction seq. number to be printed.
60 'tick_start':0, # The first tick to be printed
61 'tick_stop':0, # The last tick to be printed
62 'tick_drift':2000, # Used to calculate the start and the end of main
63 # loop. We assume here that the instructions are not
64 # out of order for more then 2000 CPU ticks,
65 # otherwise the print may not start/stop
66 # at the time specified by tick_start/stop.
67 'only_committed':0 # Set if only committed instructions are printed.
67 'only_committed':0, # Set if only committed instructions are printed.
68}
69
70def process_trace(trace, outfile, cycle_time, width, color, timestamps,
68}
69
70def process_trace(trace, outfile, cycle_time, width, color, timestamps,
71 committed_only, start_tick, stop_tick, start_sn, stop_sn):
71 committed_only, store_completions, start_tick, stop_tick, start_sn, stop_sn):
72 global insts
73
74 insts['sn_start'] = start_sn
75 insts['sn_stop'] = stop_sn
76 insts['tick_start'] = start_tick
77 insts['tick_stop'] = stop_tick
78 insts['tick_drift'] = insts['tick_drift'] * cycle_time
79 insts['only_committed'] = committed_only
80 line = None
81 fields = None
82
72 global insts
73
74 insts['sn_start'] = start_sn
75 insts['sn_stop'] = stop_sn
76 insts['tick_start'] = start_tick
77 insts['tick_stop'] = stop_tick
78 insts['tick_drift'] = insts['tick_drift'] * cycle_time
79 insts['only_committed'] = committed_only
80 line = None
81 fields = None
82
83 # Read the first line
84 line = trace.readline()
85 if not line: return
86 fields = line.split(':')
87
88 # Skip lines up to the starting tick
89 if start_tick != 0:
90 while True:
83 # Skip lines up to the starting tick
84 if start_tick != 0:
85 while True:
91 if fields[0] != 'O3PipeView': continue
92 if (int(fields[2]) > 0 and
93 int(fields[2]) >= start_tick-insts['tick_drift']): break
94 line = trace.readline()
95 if not line: return
96 fields = line.split(':')
86 line = trace.readline()
87 if not line: return
88 fields = line.split(':')
97
98 # Skip lines up to the starting sequence number
99 if start_sn != 0:
100 while True:
101 if fields[0] != 'O3PipeView': continue
89 if fields[0] != 'O3PipeView': continue
102 if (fields[1] == 'fetch' and
103 int(fields[5]) >= (start_sn-insts['max_threshold'])):
104 break
90 if int(fields[2]) >= start_tick: break
91 elif start_sn != 0:
92 while True:
105 line = trace.readline()
106 if not line: return
107 fields = line.split(':')
93 line = trace.readline()
94 if not line: return
95 fields = line.split(':')
96 if fields[0] != 'O3PipeView': continue
97 if fields[1] == 'fetch' and int(fields[5]) >= start_sn: break
98 else:
99 line = trace.readline()
100 if not line: return
101 fields = line.split(':')
108
109 # Skip lines up to next instruction fetch
110 while fields[0] != 'O3PipeView' or fields[1] != 'fetch':
111 line = trace.readline()
112 if not line: return
113 fields = line.split(':')
114
115 # Print header
116 outfile.write('// f = fetch, d = decode, n = rename, p = dispatch, '
102
103 # Skip lines up to next instruction fetch
104 while fields[0] != 'O3PipeView' or fields[1] != 'fetch':
105 line = trace.readline()
106 if not line: return
107 fields = line.split(':')
108
109 # Print header
110 outfile.write('// f = fetch, d = decode, n = rename, p = dispatch, '
117 'i = issue, c = complete, r = retire\n\n')
111 'i = issue, c = complete, r = retire')
112
113 if store_completions:
114 outfile.write(', s = store-complete')
115 outfile.write('\n\n')
116
118 outfile.write(' ' + 'timeline'.center(width) +
119 ' ' + 'tick'.center(15) +
120 ' ' + 'pc.upc'.center(12) +
121 ' ' + 'disasm'.ljust(25) +
117 outfile.write(' ' + 'timeline'.center(width) +
118 ' ' + 'tick'.center(15) +
119 ' ' + 'pc.upc'.center(12) +
120 ' ' + 'disasm'.ljust(25) +
122 ' ' + 'seq_num'.center(15))
121 ' ' + 'seq_num'.center(10))
123 if timestamps:
124 outfile.write('timestamps'.center(25))
125 outfile.write('\n')
126
127 # Region of interest
128 curr_inst = {}
129 while True:
130 if fields[0] == 'O3PipeView':
131 curr_inst[fields[1]] = int(fields[2])
132 if fields[1] == 'fetch':
133 if ((stop_tick > 0 and int(fields[2]) > stop_tick+insts['tick_drift']) or
134 (stop_sn > 0 and int(fields[5]) > (stop_sn+insts['max_threshold']))):
135 print_insts(outfile, cycle_time, width, color, timestamps, 0)
136 return
137 (curr_inst['pc'], curr_inst['upc']) = fields[3:5]
138 curr_inst['sn'] = int(fields[5])
139 curr_inst['disasm'] = ' '.join(fields[6][:-1].split())
140 elif fields[1] == 'retire':
122 if timestamps:
123 outfile.write('timestamps'.center(25))
124 outfile.write('\n')
125
126 # Region of interest
127 curr_inst = {}
128 while True:
129 if fields[0] == 'O3PipeView':
130 curr_inst[fields[1]] = int(fields[2])
131 if fields[1] == 'fetch':
132 if ((stop_tick > 0 and int(fields[2]) > stop_tick+insts['tick_drift']) or
133 (stop_sn > 0 and int(fields[5]) > (stop_sn+insts['max_threshold']))):
134 print_insts(outfile, cycle_time, width, color, timestamps, 0)
135 return
136 (curr_inst['pc'], curr_inst['upc']) = fields[3:5]
137 curr_inst['sn'] = int(fields[5])
138 curr_inst['disasm'] = ' '.join(fields[6][:-1].split())
139 elif fields[1] == 'retire':
141 queue_inst(outfile, curr_inst, cycle_time, width, color, timestamps)
140 if curr_inst['retire'] == 0:
141 curr_inst['disasm'] = '-----' + curr_inst['disasm']
142 if store_completions:
143 curr_inst[fields[3]] = int(fields[4])
144 queue_inst(outfile, curr_inst, cycle_time, width, color, timestamps, store_completions)
145
142 line = trace.readline()
146 line = trace.readline()
143 if not line: return
147 if not line:
148 print_insts(outfile, cycle_time, width, color, timestamps, store_completions, 0)
149 return
144 fields = line.split(':')
145
146
147#Sorts out instructions according to sequence number
148def compare_by_sn(a, b):
149 return cmp(a['sn'], b['sn'])
150
151# Puts new instruction into the print queue.
152# Sorts out and prints instructions when their number reaches threshold value
150 fields = line.split(':')
151
152
153#Sorts out instructions according to sequence number
154def compare_by_sn(a, b):
155 return cmp(a['sn'], b['sn'])
156
157# Puts new instruction into the print queue.
158# Sorts out and prints instructions when their number reaches threshold value
153def queue_inst(outfile, inst, cycle_time, width, color, timestamps):
159def queue_inst(outfile, inst, cycle_time, width, color, timestamps, store_completions):
154 global insts
155 l_copy = copy.deepcopy(inst)
156 insts['queue'].append(l_copy)
157 if len(insts['queue']) > insts['max_threshold']:
160 global insts
161 l_copy = copy.deepcopy(inst)
162 insts['queue'].append(l_copy)
163 if len(insts['queue']) > insts['max_threshold']:
158 print_insts(outfile, cycle_time, width, color, timestamps, insts['min_threshold'])
164 print_insts(outfile, cycle_time, width, color, timestamps, store_completions, insts['min_threshold'])
159
160# Sorts out and prints instructions in print queue
165
166# Sorts out and prints instructions in print queue
161def print_insts(outfile, cycle_time, width, color, timestamps, lower_threshold):
167def print_insts(outfile, cycle_time, width, color, timestamps, store_completions, lower_threshold):
162 global insts
163 insts['queue'].sort(compare_by_sn)
164 while len(insts['queue']) > lower_threshold:
165 print_item=insts['queue'].pop(0)
166 # As the instructions are processed out of order the main loop starts
167 # earlier then specified by start_sn/tick and finishes later then what
168 # is defined in stop_sn/tick.
169 # Therefore, here we have to filter out instructions that reside out of

--- 4 unchanged lines hidden (view full) ---

174 continue; # later then the ending sequence number
175 if (insts['tick_start'] > 0 and print_item['fetch'] < insts['tick_start']):
176 continue; # earlier then the starting tick number
177 if (insts['tick_stop'] > 0 and print_item['fetch'] > insts['tick_stop']):
178 continue; # later then the ending tick number
179
180 if (insts['only_committed'] != 0 and print_item['retire'] == 0):
181 continue; # retire is set to zero if it hasn't been completed
168 global insts
169 insts['queue'].sort(compare_by_sn)
170 while len(insts['queue']) > lower_threshold:
171 print_item=insts['queue'].pop(0)
172 # As the instructions are processed out of order the main loop starts
173 # earlier then specified by start_sn/tick and finishes later then what
174 # is defined in stop_sn/tick.
175 # Therefore, here we have to filter out instructions that reside out of

--- 4 unchanged lines hidden (view full) ---

180 continue; # later then the ending sequence number
181 if (insts['tick_start'] > 0 and print_item['fetch'] < insts['tick_start']):
182 continue; # earlier then the starting tick number
183 if (insts['tick_stop'] > 0 and print_item['fetch'] > insts['tick_stop']):
184 continue; # later then the ending tick number
185
186 if (insts['only_committed'] != 0 and print_item['retire'] == 0):
187 continue; # retire is set to zero if it hasn't been completed
182 print_inst(outfile, print_item, cycle_time, width, color, timestamps)
188 print_inst(outfile, print_item, cycle_time, width, color, timestamps, store_completions)
183
184# Prints a single instruction
189
190# Prints a single instruction
185def print_inst(outfile, inst, cycle_time, width, color, timestamps):
191def print_inst(outfile, inst, cycle_time, width, color, timestamps, store_completions):
186 if color:
187 from m5.util.terminal import termcap
188 else:
189 from m5.util.terminal import no_termcap as termcap
190 # Pipeline stages
191 stages = [{'name': 'fetch',
192 'color': termcap.Blue + termcap.Reverse,
193 'shorthand': 'f'},

--- 9 unchanged lines hidden (view full) ---

203 {'name': 'issue',
204 'color': termcap.Red + termcap.Reverse,
205 'shorthand': 'i'},
206 {'name': 'complete',
207 'color': termcap.Cyan + termcap.Reverse,
208 'shorthand': 'c'},
209 {'name': 'retire',
210 'color': termcap.Blue + termcap.Reverse,
192 if color:
193 from m5.util.terminal import termcap
194 else:
195 from m5.util.terminal import no_termcap as termcap
196 # Pipeline stages
197 stages = [{'name': 'fetch',
198 'color': termcap.Blue + termcap.Reverse,
199 'shorthand': 'f'},

--- 9 unchanged lines hidden (view full) ---

209 {'name': 'issue',
210 'color': termcap.Red + termcap.Reverse,
211 'shorthand': 'i'},
212 {'name': 'complete',
213 'color': termcap.Cyan + termcap.Reverse,
214 'shorthand': 'c'},
215 {'name': 'retire',
216 'color': termcap.Blue + termcap.Reverse,
211 'shorthand': 'r'}]
217 'shorthand': 'r'}
218 ]
219 if store_completions:
220 stages.append(
221 {'name': 'store',
222 'color': termcap.Yellow + termcap.Reverse,
223 'shorthand': 's'})
212
213 # Print
214
215 time_width = width * cycle_time
216 base_tick = (inst['fetch'] / time_width) * time_width
217
218 # Find out the time of the last event - it may not
219 # be 'retire' if the instruction is not comlpeted.
220 last_event_time = max(inst['fetch'], inst['decode'],inst['rename'],
224
225 # Print
226
227 time_width = width * cycle_time
228 base_tick = (inst['fetch'] / time_width) * time_width
229
230 # Find out the time of the last event - it may not
231 # be 'retire' if the instruction is not comlpeted.
232 last_event_time = max(inst['fetch'], inst['decode'],inst['rename'],
221 inst['dispatch'],inst['issue'], inst['complete'], inst['retire'])
233 inst['dispatch'],inst['issue'], inst['complete'], inst['retire'])
234 if store_completions:
235 last_event_time = max(last_event_time, inst['store'])
222
223 # Timeline shorter then time_width is printed in compact form where
224 # the print continues at the start of the same line.
225 if ((last_event_time - inst['fetch']) < time_width):
226 num_lines = 1 # compact form
227 else:
228 num_lines = ((last_event_time - base_tick) / time_width) + 1
229

--- 33 unchanged lines hidden (view full) ---

263 curr_color = stages[event[2]]['color']
264 else:
265 curr_color = termcap.Normal
266
267 pos = (event[0] / cycle_time) + 1
268 outfile.write(curr_color + dot * (width - pos) + termcap.Normal +
269 ']-(' + str(base_tick + i * time_width).rjust(15) + ') ')
270 if i == 0:
236
237 # Timeline shorter then time_width is printed in compact form where
238 # the print continues at the start of the same line.
239 if ((last_event_time - inst['fetch']) < time_width):
240 num_lines = 1 # compact form
241 else:
242 num_lines = ((last_event_time - base_tick) / time_width) + 1
243

--- 33 unchanged lines hidden (view full) ---

277 curr_color = stages[event[2]]['color']
278 else:
279 curr_color = termcap.Normal
280
281 pos = (event[0] / cycle_time) + 1
282 outfile.write(curr_color + dot * (width - pos) + termcap.Normal +
283 ']-(' + str(base_tick + i * time_width).rjust(15) + ') ')
284 if i == 0:
271 outfile.write('%s.%s %s [%s]' % (
285 outfile.write('%s.%s %s [%s]' % (
272 inst['pc'].rjust(10),
273 inst['upc'],
274 inst['disasm'].ljust(25),
286 inst['pc'].rjust(10),
287 inst['upc'],
288 inst['disasm'].ljust(25),
275 str(inst['sn']).rjust(15)))
289 str(inst['sn']).rjust(10)))
276 if timestamps:
277 outfile.write(' f=%s, r=%s' % (inst['fetch'], inst['retire']))
278 outfile.write('\n')
279 else:
280 outfile.write('...'.center(12) + '\n')
281
282
283def validate_range(my_range):

--- 40 unchanged lines hidden (view full) ---

324 parser.add_option(
325 '--timestamps',
326 action='store_true', default=False,
327 help="print fetch and retire timestamps (default: '%default')")
328 parser.add_option(
329 '--only_committed',
330 action='store_true', default=False,
331 help="display only committed (completed) instructions (default: '%default')")
290 if timestamps:
291 outfile.write(' f=%s, r=%s' % (inst['fetch'], inst['retire']))
292 outfile.write('\n')
293 else:
294 outfile.write('...'.center(12) + '\n')
295
296
297def validate_range(my_range):

--- 40 unchanged lines hidden (view full) ---

338 parser.add_option(
339 '--timestamps',
340 action='store_true', default=False,
341 help="print fetch and retire timestamps (default: '%default')")
342 parser.add_option(
343 '--only_committed',
344 action='store_true', default=False,
345 help="display only committed (completed) instructions (default: '%default')")
346 parser.add_option(
347 '--store_completions',
348 action='store_true', default=False,
349 help="additionally display store completion ticks (default: '%default')")
332 (options, args) = parser.parse_args()
333 if len(args) != 1:
334 parser.error('incorrect number of arguments')
335 sys.exit(1)
336 tick_range = validate_range(options.tick_range)
337 if not tick_range:
338 parser.error('invalid range')
339 sys.exit(1)
340 inst_range = validate_range(options.inst_range)
341 if not inst_range:
342 parser.error('invalid range')
343 sys.exit(1)
344 # Process trace
345 print 'Processing trace... ',
346 with open(args[0], 'r') as trace:
347 with open(options.outfile, 'w') as out:
348 process_trace(trace, out, options.cycle_time, options.width,
349 options.color, options.timestamps,
350 (options, args) = parser.parse_args()
351 if len(args) != 1:
352 parser.error('incorrect number of arguments')
353 sys.exit(1)
354 tick_range = validate_range(options.tick_range)
355 if not tick_range:
356 parser.error('invalid range')
357 sys.exit(1)
358 inst_range = validate_range(options.inst_range)
359 if not inst_range:
360 parser.error('invalid range')
361 sys.exit(1)
362 # Process trace
363 print 'Processing trace... ',
364 with open(args[0], 'r') as trace:
365 with open(options.outfile, 'w') as out:
366 process_trace(trace, out, options.cycle_time, options.width,
367 options.color, options.timestamps,
350 options.only_committed, *(tick_range + inst_range))
368 options.only_committed, options.store_completions,
369 *(tick_range + inst_range))
351 print 'done!'
352
353
354if __name__ == '__main__':
355 sys.path.append(os.path.join(
356 os.path.dirname(os.path.abspath(__file__)),
357 '..', 'src', 'python'))
358 main()
370 print 'done!'
371
372
373if __name__ == '__main__':
374 sys.path.append(os.path.join(
375 os.path.dirname(os.path.abspath(__file__)),
376 '..', 'src', 'python'))
377 main()