Skip to content

Commit

Permalink
treewide: Extend visualize.py as required to include CVA6 trace
Browse files Browse the repository at this point in the history
  • Loading branch information
colluca committed Aug 11, 2024
1 parent 225e051 commit 11f0e93
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
4 changes: 3 additions & 1 deletion target/common/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ JOINT_PERF_DUMP = $(LOGS_DIR)/perf.json
ROI_DUMP = $(LOGS_DIR)/roi.json
VISUAL_TRACE = $(LOGS_DIR)/trace.json

VISUALIZE_PY_FLAGS += --tracevis "$(BINARY) $(SNITCH_TXT_TRACES) --addr2line $(ADDR2LINE) -f snitch"

.PHONY: traces annotate visual-trace clean-traces clean-annotate clean-perf clean-visual-trace
traces: $(TXT_TRACES)
annotate: $(ANNOTATED_TRACES)
Expand Down Expand Up @@ -243,4 +245,4 @@ $(ROI_DUMP): $(JOINT_PERF_DUMP) $(ROI_SPEC) $(ROI_PY)
$(ROI_PY) $(JOINT_PERF_DUMP) $(ROI_SPEC) --cfg $(CFG) -o $@

$(VISUAL_TRACE): $(ROI_DUMP) $(VISUALIZE_PY)
$(VISUALIZE_PY) $(ROI_DUMP) --traces $(SNITCH_TXT_TRACES) --elf $(BINARY) --addr2line $(ADDR2LINE) -o $@
$(VISUALIZE_PY) $(ROI_DUMP) $(VISUALIZE_PY_FLAGS) -o $@
32 changes: 14 additions & 18 deletions util/bench/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,17 @@ def main():
metavar='<input>',
help='Input JSON file')
parser.add_argument(
'--traces',
metavar='<trace>',
nargs='*',
help='Simulation traces to process')
parser.add_argument(
'--elf',
nargs='?',
help='ELF from which the traces were generated')
'--tracevis',
action='append',
default=[],
help='Argument string to pass down to tracevis, to generate additional events.')
parser.add_argument(
'-o',
'--output',
metavar='<json>',
nargs='?',
default='trace.json',
help='Output JSON file')
parser.add_argument(
'--addr2line',
metavar='<path>',
nargs='?',
default='addr2line',
help='`addr2line` binary to use for parsing')
args = parser.parse_args()

# TraceViewer events
Expand Down Expand Up @@ -104,10 +94,16 @@ def main():

# Optionally extract also instruction-level events
# from the simulation traces
if args.traces and args.elf:
events += tracevis.parse_traces(args.traces, start=0, end=-1, fmt='snitch',
addr2line=args.addr2line, use_time=True, pid=1,
cache=True, elf=args.elf, collapse_call_stack=True)
for tvargs in args.tracevis:
# Break tracevis argument string into a list of arguments
tvargs = tvargs.split()
# Add default arguments, and parse all tracevis arguments
tvargs.append('--time')
tvargs.append('--collapse-call-stack')
tvargs = vars(tracevis.parse_args(tvargs))
# Add more arguments, and get tracevis events
tvargs['pid'] = 1
events += tracevis.parse_traces(**tvargs)

# Create TraceViewer JSON object
tvobj = {}
Expand Down
18 changes: 9 additions & 9 deletions util/trace/tracevis.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ def flush(lah, buf, **kwargs):
event['dur'] = 1 if fmt == 'banshee' else duration
# The thread ID is used to group events in a single TraceViewer row
if not collapse_call_stack:
event['tid'] = a2l_info.function_stack[0]['func']
stack = a2l_info.function_stack()
if stack is not None:
event['tid'] = stack[0]['func']
if fmt == 'banshee':
# Banshee stores all traces in a single file
event['tid'] = priv
Expand Down Expand Up @@ -272,13 +274,11 @@ def parse_traces(traces, **kwargs):

# Iterate traces
events = []
for i, filename in enumerate(traces):
for filename in traces:

# Extract hartid from filename or use current index
# TODO doesn't work with hex numbers
# parsed_nums = re.findall(r'\d+', filename)
# hartid = int(parsed_nums[-1]) if len(parsed_nums) else i
hartid = i
# Extract hartid from filename
pattern = r'trace_hart_([0-9a-fA-F]+)\.txt$'
hartid = int(re.search(pattern, filename).group(1), 16)

# Extract TraceViewer events from trace
trace_events = parse_trace(filename, **kwargs)
Expand Down Expand Up @@ -319,7 +319,7 @@ def main(**kwargs):


# Parse command-line args
def parse_args():
def parse_args(args=None):
# Argument parsing
parser = argparse.ArgumentParser('tracevis', allow_abbrev=True)
parser.add_argument(
Expand Down Expand Up @@ -379,7 +379,7 @@ def parse_args():
type=int,
default=-1,
help='Last line to parse (inclusive)')
return parser.parse_args()
return parser.parse_args(args)


if __name__ == '__main__':
Expand Down

0 comments on commit 11f0e93

Please sign in to comment.