[scripts] Format tracevis
+#!/usr/bin/env python3
+
+# Copyright 2021 ETH Zurich and University of Bologna.
+# Licensed under the Apache License, Version 2.0, see LICENSE for details.
+# SPDX-License-Identifier: Apache-2.0
+
+# This script parses the traces generated by Snitch and creates a JSON file
+# that can be visualized by
+# [Trace-Viewer](https://github.com/catapult-project/catapult/tree/master/tracing)
+# In Chrome, open `about:tracing` and load the JSON file to view it.
+#
+# This script is inspired by https://github.com/SalvatoreDiGirolamo/tracevis
+# Author: Noah Huetter <huettern@student.ethz.ch>
+# Samuel Riedel <sriedel@iis.ee.ethz.ch>
import re, os, sys
import progressbar
@@ -28,10 +42,12 @@ re_acc_line = re.compile(ACC_LINE_REGEX)
buf = []
+
def flush(buf, hartid):
# get function names
pcs = [x[3] for x in buf]
- a2ls = os.popen(f'addr2line -e {elf} -f -a -i {pcs}').read().split('\n')[:-1]
+ a2ls = os.popen(
+ f'addr2line -e {elf} -f -a -i {pcs}').read().split('\n')[:-1]
for i in range(len(buf)-1):
(time, cyc, priv, pc, instr, args) = buf.pop(0)
@@ -76,20 +92,25 @@ def flush(buf, hartid):
f' "time": "{arg_cycles}", "Origin": "{arg_coords}", "inline": "{inlined}"'
f'}}}},'))
+
last_time = last_cyc = 0
+
+
def parse_line(line, hartid):
global last_time, last_cyc
# print(line)
match = re_line.match(line)
if match:
- (time, cyc, priv, pc, instr, args) = tuple([match.group(i+1).strip() for i in range(re_line.groups)])
+ (time, cyc, priv, pc, instr, args) = tuple(
+ [match.group(i+1).strip() for i in range(re_line.groups)])
# print(match)
if not match:
# match accelerator line with same timestamp as before
match = re_acc_line.match(line)
if match:
- (priv, pc, instr, args) = tuple([match.group(i+1).strip() for i in range(re_acc_line.groups)])
+ (priv, pc, instr, args) = tuple(
+ [match.group(i+1).strip() for i in range(re_acc_line.groups)])
# use time,cyc from last line
time, cyc = last_time, last_cyc
else:
@@ -103,6 +124,7 @@ def parse_line(line, hartid):
flush(buf, hartid)
return 0
+
fails = lines = 0
