Skip to content

Commit 3311a96

Browse files
committed
feat: add z01x runtime and simulated time log parsing
Get Z01X closer to existing sim tools (xcelium and VCS) by implementing log runtime and simtime parsing for DVSim to report. Signed-off-by: Alex Jones <alex.jones@lowrisc.org>
1 parent ef416e4 commit 3311a96

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

src/dvsim/sim/tool/z01x.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
"""EDA tool plugin providing Z01X support to DVSim."""
66

7+
from collections.abc import Sequence
78
from typing import TYPE_CHECKING
89

910
from dvsim.sim.tool.vcs import VCS
@@ -17,6 +18,92 @@
1718
class Z01X(VCS):
1819
"""Implement Z01X tool support."""
1920

21+
RUNTIME_COL = 2
22+
SIMTIME_COL = 3
23+
REQUIRED_COLS = max(RUNTIME_COL, SIMTIME_COL) + 1
24+
25+
@staticmethod
26+
def _get_execution_summary(log_text: Sequence[str]) -> list[str]:
27+
summary_start: int | None = None
28+
summary_end: int | None = None
29+
for i, line in reversed(list(enumerate(log_text))):
30+
if line.strip() == "Execution Summary":
31+
summary_start = i
32+
break
33+
if summary_end is None and set(line) == set("="):
34+
summary_end = i
35+
if summary_start is None:
36+
msg = f"Execution summary not found in log (start={summary_start}, end={summary_end})"
37+
raise RuntimeError(msg)
38+
39+
for line in reversed(log_text[summary_start + 1 : summary_end]):
40+
if "|" not in line:
41+
continue
42+
return [c.strip() for c in line.split("|")]
43+
44+
msg = f"Summary table not found in log (start={summary_start}, end={summary_end})"
45+
raise RuntimeError(msg)
46+
47+
@staticmethod
48+
def get_job_runtime(log_text: Sequence[str]) -> tuple[float, str]:
49+
"""Return the job runtime (wall clock time) along with its units.
50+
51+
EDA tools indicate how long the job ran in terms of CPU time in the log
52+
file. This method invokes the tool specific method which parses the log
53+
text and returns the runtime as a floating point value followed by its
54+
units as a tuple.
55+
56+
Args:
57+
log_text: is the job's log file contents as a list of lines.
58+
59+
Returns:
60+
a tuple of (runtime, units).
61+
62+
Raises:
63+
RuntimeError: exception if the search pattern is not found.
64+
65+
"""
66+
summary_totals = Z01X._get_execution_summary(log_text)
67+
if len(summary_totals) < Z01X.REQUIRED_COLS:
68+
msg = f"Summary table contained less columns ({len(summary_totals)}) than expected"
69+
raise RuntimeError(msg)
70+
71+
try: # Quite fragile: columns are hardcoded.
72+
return float(summary_totals[Z01X.RUNTIME_COL]), "s"
73+
except ValueError as e:
74+
msg = f"Found invalid runtime value '{summary_totals[Z01X.RUNTIME_COL]}'"
75+
raise RuntimeError(msg) from e
76+
77+
@staticmethod
78+
def get_simulated_time(log_text: Sequence[str]) -> tuple[float, str]:
79+
"""Return the simulated time along with its units.
80+
81+
EDA tools indicate how long the design was simulated for in the log file.
82+
This method invokes the tool specific method which parses the log text and
83+
returns the simulated time as a floating point value followed by its
84+
units (typically, pico|nano|micro|milliseconds) as a tuple.
85+
86+
Args:
87+
log_text: is the job's log file contents as a list of lines.
88+
89+
Returns:
90+
a tuple of (simulated time, units).
91+
92+
Raises:
93+
RuntimeError: exception if the search pattern is not found.
94+
95+
"""
96+
summary_totals = Z01X._get_execution_summary(log_text)
97+
if len(summary_totals) < Z01X.REQUIRED_COLS:
98+
msg = f"Summary table contained less columns ({len(summary_totals)}) than expected"
99+
raise RuntimeError(msg)
100+
101+
try: # Quite fragile: columns are hardcoded.
102+
return float(summary_totals[Z01X.SIMTIME_COL]), "s"
103+
except ValueError as e:
104+
msg = f"Found invalid simulated time value '{summary_totals[Z01X.SIMTIME_COL]}'"
105+
raise RuntimeError(msg) from e
106+
20107
@staticmethod
21108
def set_additional_attrs(deploy: "Deploy") -> None:
22109
"""Define any additional tool-specific attrs on the deploy object.

0 commit comments

Comments
 (0)