Skip to content

Commit

Permalink
gen_trace.py: Print line number on exception
Browse files Browse the repository at this point in the history
  • Loading branch information
colluca committed Aug 11, 2024
1 parent 587373d commit 460ae8e
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions util/trace/gen_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
from ctypes import c_int32, c_uint32
from collections import deque, defaultdict
from pathlib import Path
import traceback
from itertools import tee, islice, chain

EXTRA_WB_WARN = 'WARNING: {} transactions still in flight for {}.'

Expand Down Expand Up @@ -1038,6 +1040,15 @@ def fmt_perf_metrics(perf_metrics: list, idx: int, omit_keys: bool = True):
return '\n'.join(ret)


# -------------------- Utils --------------------


def current_and_next(iterable):
currs, nexts = tee(iterable, 2)
nexts = chain(islice(nexts, 1, None), [None])
return zip(currs, nexts)


# -------------------- Main --------------------


Expand Down Expand Up @@ -1115,16 +1126,26 @@ def main():
] # all values initially 0, also 'start' time of measurement 0
perf_metrics[0]['start'] = None
# Parse input line by line
for line in line_iter:
for lineno, (line, nextl) in enumerate(current_and_next(line_iter)):
if line:
ann_insn, time_info, empty = annotate_insn(
line, gpr_wb_info, fpr_wb_info, fseq_info, perf_metrics, False,
time_info, args.offl, not args.saddr, args.permissive, dma_trans)
if perf_metrics[0]['start'] is None:
perf_metrics[0]['tstart'] = time_info[0] / 1000
perf_metrics[0]['start'] = time_info[1]
if not empty:
print(ann_insn, file=file)
try:
ann_insn, time_info, empty = annotate_insn(
line, gpr_wb_info, fpr_wb_info, fseq_info, perf_metrics, False,
time_info, args.offl, not args.saddr, args.permissive, dma_trans)
if perf_metrics[0]['start'] is None:
perf_metrics[0]['tstart'] = time_info[0] / 1000
perf_metrics[0]['start'] = time_info[1]
if not empty:
print(ann_insn, file=file)
except Exception:
message = 'Exception occured while processing '
if not nextl:
message += 'last line. Did the simulation terminate?'
else:
message += 'line {lineno}.'
print(traceback.format_exc(), file=sys.stderr)
print(message, file=sys.stderr)
return 1
else:
break # Nothing more in pipe, EOF
perf_metrics[-1]['tend'] = time_info[0] / 1000
Expand Down

0 comments on commit 460ae8e

Please sign in to comment.