#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """What a lockstep scenario exercised: boundary kinds, opcodes executed, stalls, writes stalled. scenario_stats.py TRACE_BINARY SCENARIO.json [...] Runs this crate's trace of each scenario and counts, so the claims about the rung 4 scenarios (WAI waiting cycles, STP, NMI, IRQ, resets, every opcode of the random-memory runs) are measured, not assumed. Stdlib only. """ from __future__ import annotations import json import subprocess import sys from collections import Counter from pathlib import Path def main() -> int: binary = sys.argv[1] for path in map(Path, sys.argv[2:]): kinds: Counter = Counter() opcodes: set[int] = set() decimal = 0 process = subprocess.Popen([binary, str(path)], stdout=subprocess.PIPE, text=True) assert process.stdout is not None for line in process.stdout: record = json.loads(line) kinds[record["kind"]] += 1 if record["kind"] == "instruction": opcodes.add(int(record["instruction"]["data"][:2], 16)) decimal += bool(record["before"]["p"] & 0x08) process.wait() scenario = json.loads(path.read_text()) stalls = len(scenario.get("stalls", ())) print( f"{path.stem}: {dict(sorted(kinds.items()))}; {len(opcodes)} distinct opcodes; " f"{decimal} instructions with D set; {stalls} stalls" ) return 0 if __name__ == "__main__": sys.exit(main())