"""Per-frame profile from a run_32x.py log of the instrumented player (m_main.c's COMM8, COMM10, COMM4), lined up with the encoder's frames.json. py -3.12 -m r32x.profile_log out32/c1v_0/run.log out32/c1v_0 """ import json import re import sys from pathlib import Path FIELD = 22_800_000 / 50 # SH-2 cycles per PAL field def main() -> None: log, enc = Path(sys.argv[1]), Path(sys.argv[2]) rows = json.loads((enc / "frames.json").read_text()) seen: dict[int, tuple[int, int, int]] = {} for line in log.read_text().splitlines(): m = re.search(r"comm \[(.*?)\]", line) if m: c = [int(x) for x in m.group(1).split(",")] # COMM2 = frames shown; the profile words belong to the frame just shown if c[1] and c[1] not in seen and c[1] <= len(rows): seen[c[1]] = (c[4], c[5], c[2]) tot = [0.0, 0.0, 0.0] for n, (dec, conv, wait) in sorted(seen.items()): r = rows[n - 1] d, cv, w = dec * 128 / FIELD, conv * 128 / FIELD, wait * 128 / FIELD tot = [tot[0] + d, tot[1] + cv, tot[2] + w] print(f"frame {n - 1:3d} {r['bytes']:5d} B skip/i0/inter/intra {r['skip']:3d}/{r['inter0']:3d}/{r['inter']:3d}/{r['intra']:3d}" f" decode {d:4.2f} convert {cv:4.2f} slave wait {w:4.2f} (fields)") n = len(seen) if n: print(f"mean over {n} frames, in fields: decode {tot[0] / n:.2f}, convert {tot[1] / n:.2f}, slave wait {tot[2] / n:.2f}") if __name__ == "__main__": main()