#!/usr/bin/env python3 """The README's profile table: shares by group from two profile.py outputs.""" import json, re, subprocess, sys, pathlib ROOT = pathlib.Path("/data/emu/pcengine-rust-fast") GROUPS = { "CORE": ["CPU core (huc6280-rust)", "frame.rs"], "BOARD": ["board.rs"], "CHIP": ["vdc/chip.rs"], "SEQ": ["vdc/sequencer.rs", "vdc/dma.rs"], "PIC": ["vdc/background.rs", "vdc/sprites.rs", "video.rs"], "CARD": ["cards.rs", "pagetable.rs"], "PSG": ["psg/chip.rs", "mixer.rs"], } out = {} for tag, path in (("BL", sys.argv[1]), ("SF", sys.argv[2])): text = subprocess.run([sys.executable, "scripts/profile.py", path], cwd=ROOT, capture_output=True, text=True, check=True).stdout block = text.split("modules (self, std charged to the caller):")[1].split("modules (self):")[0] shares = {name.strip(): float(pct) for pct, name in re.findall(r"^\s*([\d.]+)%\s+(.*)$", block, re.M)} for group, names in GROUPS.items(): out[f"{tag}_{group}"] = f"{sum(shares.get(n, 0.0) for n in names):.1f}%" print(tag, {g: out[f"{tag}_{g}"] for g in GROUPS}, "other", f"{100 - sum(float(out[f'{tag}_{g}'][:-1]) for g in GROUPS):.1f}%") (ROOT / "external" / "profile-shares.json").write_text(json.dumps(out, indent=1))