|
4 | 4 |
|
5 | 5 | """EDA tool plugin providing Z01X support to DVSim.""" |
6 | 6 |
|
| 7 | +from collections.abc import Sequence |
7 | 8 | from typing import TYPE_CHECKING |
8 | 9 |
|
9 | 10 | from dvsim.sim.tool.vcs import VCS |
|
17 | 18 | class Z01X(VCS): |
18 | 19 | """Implement Z01X tool support.""" |
19 | 20 |
|
| 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 | + |
20 | 107 | @staticmethod |
21 | 108 | def set_additional_attrs(deploy: "Deploy") -> None: |
22 | 109 | """Define any additional tool-specific attrs on the deploy object. |
|
0 commit comments