diff options
Diffstat (limited to 'build-support')
| -rw-r--r-- | build-support/capture-alloc-sources.py | 11 | ||||
| -rw-r--r-- | build-support/measure-alloc.py | 12 | ||||
| -rw-r--r-- | build-support/spill-matrix.py | 21 |
3 files changed, 25 insertions, 19 deletions
diff --git a/build-support/capture-alloc-sources.py b/build-support/capture-alloc-sources.py index f474ac55..e12f9cc6 100644 --- a/build-support/capture-alloc-sources.py +++ b/build-support/capture-alloc-sources.py @@ -2,9 +2,10 @@ from pathlib import Path import subprocess,sys,os root=Path(__file__).resolve().parents[1] -ch=int(sys.argv[1]); chapter=root/f'chapter{ch}' -if ch not in range(21,25): raise SystemExit("Capture supports chapters 21-24") -out=root/'build/dynamic-stats'/str(ch); out.mkdir(parents=True,exist_ok=True) +name=sys.argv[1].removeprefix('chapter') +if name not in ('21','22','23','24b'): raise SystemExit("Capture supports chapters 21, 22, 23, 24b") +chapter=root/f'chapter{name}' +out=root/'build/dynamic-stats'/name; out.mkdir(parents=True,exist_ok=True) src=(chapter/'src/test/java/com/seaofnodes/simple/SpillStats.java').read_text() needle='String test = ACTIVE._test.getTestClass().getSimpleName()+"."+ACTIVE._test.getMethodName();' extra=''' @@ -15,7 +16,7 @@ extra=''' java.nio.file.Files.writeString(dir.resolve(name),code._src); java.nio.file.Files.writeString(dir.resolve("index.tsv"),cohort+"\\t"+test+"\\t"+cpu+"\\t"+abi+"\\t"+name+"\\n",java.nio.file.StandardOpenOption.CREATE,java.nio.file.StandardOpenOption.APPEND); } catch(java.io.IOException e) { throw new RuntimeException(e); } -'''.replace('CH',str(ch)) +'''.replace('CH',name) assert needle in src src=src.replace(needle,needle+extra).replace('private static SpillStats ACTIVE;','private static SpillStats ACTIVE;\n private static int _capture;') (out/'SpillStats.java').write_text(src,newline='\n') @@ -25,4 +26,4 @@ idx=out/'captured/index.tsv' if idx.exists(): idx.write_text('') with (out/'capture.log').open('w') as log: subprocess.run(['java','-ea','-cp',str(out)+os.pathsep+cp,'com.seaofnodes.simple.SpillStats'],cwd=chapter,stdout=log,stderr=subprocess.STDOUT,check=True) -print(ch,'captured',len(idx.read_text().splitlines())) +print(name,'captured',len(idx.read_text().splitlines())) diff --git a/build-support/measure-alloc.py b/build-support/measure-alloc.py index ed899713..c563eea7 100644 --- a/build-support/measure-alloc.py +++ b/build-support/measure-alloc.py @@ -1,9 +1,11 @@ """Compile the shared measurement harness against one chapter's existing classes.""" from pathlib import Path import json,os,re,subprocess,sys -root=Path(__file__).resolve().parents[1]; ch=int(sys.argv[1]); chapter=root/f'chapter{ch}' -if ch not in range(21,26): raise SystemExit("Dynamic measurement supports chapters 21-25") -out=root/'build/dynamic-stats'/str(ch);out.mkdir(parents=True,exist_ok=True) +root=Path(__file__).resolve().parents[1]; name=sys.argv[1].removeprefix('chapter') +slots={'21':21,'22':22,'23':23,'24b':24,'28b':25} +if name not in slots: raise SystemExit("Dynamic measurement supports chapters 21, 22, 23, 24b, 28b") +ch=slots[name]; chapter=root/f'chapter{name}' +out=root/'build/dynamic-stats'/name;out.mkdir(parents=True,exist_ok=True) src=(root/'build-support/AllocMetrics.java.in').read_text() subs={'CHAPTER':str(ch),'OPSTART':'e.opStart(n)' if ch==25 else 'e._opStart[n._nid]', 'OPLEN':'e.opLen(n)' if ch==25 else 'e._opLen[n._nid]', @@ -26,7 +28,7 @@ cp=os.pathsep.join([str(chapter/'build/classes/main'),str(chapter/'build/classes subprocess.run(['javac','-cp',cp,'-d',str(out),str(out/'Measure.java')],check=True) subprocess.run(['javac','-cp',cp,'-d',str(out),*[str(p) for p in (root/'isa/src/test-support/java/com/seaofnodes/isa/eval').glob('*.java')]],check=True) if ch==25: - p=root/'chapter25/src/test/java/com/seaofnodes/simple/spill' + p=root/'chapter28b/src/test/java/com/seaofnodes/simple/spill' index=out/'index.tsv' rows=[] for line in (p/'cohorts.tsv').read_text().splitlines(): @@ -42,4 +44,4 @@ if ch==25: else:index=out/'captured/index.tsv' with (out/'dynamic.log').open('w') as log: subprocess.run(['java','-ea','-cp',str(out)+os.pathsep+cp,'Measure',str(index)],cwd=chapter,stdout=log,stderr=subprocess.STDOUT,check=True) -print(ch, 'done') +print(name, 'done') diff --git a/build-support/spill-matrix.py b/build-support/spill-matrix.py index 9ee8f7eb..422be3a9 100644 --- a/build-support/spill-matrix.py +++ b/build-support/spill-matrix.py @@ -9,6 +9,9 @@ import sys ROOT = Path(__file__).resolve().parent.parent CHAPTERS = range(20, 26) +# Cohort IDs are historical test identities. Compiler directories follow the +# final teaching sequence; never silently reuse logs from the retired 24/25. +COMPILERS = {c: str(c) for c in CHAPTERS} | {24: "24b", 25: "28b"} START = "<!-- spill-matrix:start -->" END = "<!-- spill-matrix:end -->" @@ -21,7 +24,7 @@ def read_log(path): def read_results(log_dir): results = {} for chapter in CHAPTERS: - path = log_dir / f"spill-matrix-{chapter}.log" + path = log_dir / f"spill-matrix-{COMPILERS[chapter]}.log" text = read_log(path) if re.search(r"FAILED|(?:[Ff]ailures|Spill golden failures): [1-9]", text): raise ValueError(f"Chapter {chapter} failed; see {path}") @@ -65,7 +68,7 @@ def read_dynamic(results): values = {} records = [] for chapter in range(21, 26): - path = ROOT / f"build/dynamic-stats/{chapter}/dynamic.log" + path = ROOT / f"build/dynamic-stats/{COMPILERS[chapter]}/dynamic.log" text = read_log(path) if "FAILED," in text: raise ValueError(f"Dynamic measurement failed; see {path}") @@ -109,7 +112,7 @@ def read_dynamic(results): def table(results, dynamic, last=25): chapters = range(20, last + 1) - lines = ["| Test cohort | Cases D / X | " + " | ".join(f"Ch {c}: Ops / RA / X" for c in chapters) + " |", + lines = ["| Historical test cohort | Cases D / X | " + " | ".join(f"Ch {COMPILERS[c]}: Ops / RA / X" for c in chapters) + " |", "|---|---:|" + "---:|" * len(chapters)] for cohort in chapters: count = len(dynamic[max(21,cohort)][cohort]) @@ -146,24 +149,24 @@ def main(): args.log_dir.mkdir(parents=True, exist_ok=True) if not args.reuse: for chapter in CHAPTERS: - path = args.log_dir / f"spill-matrix-{chapter}.log" + path = args.log_dir / f"spill-matrix-{COMPILERS[chapter]}.log" print(f"Measuring chapter {chapter}: {path}", flush=True) with path.open("wb") as log: - run = subprocess.run(["make", "-C", str(ROOT / f"chapter{chapter}"), "spill-stats"], + run = subprocess.run(["make", "-C", str(ROOT / f"chapter{COMPILERS[chapter]}"), "spill-stats"], stdout=log, stderr=subprocess.STDOUT) if run.returncode: raise ValueError(f"Chapter {chapter} failed (exit {run.returncode}); see {path}") for chapter in range(21, 26): if chapter < 25: - subprocess.run([sys.executable, str(ROOT / "build-support/capture-alloc-sources.py"), str(chapter)], check=True) - subprocess.run([sys.executable, str(ROOT / "build-support/measure-alloc.py"), str(chapter)], check=True) + subprocess.run([sys.executable, str(ROOT / "build-support/capture-alloc-sources.py"), COMPILERS[chapter]], check=True) + subprocess.run([sys.executable, str(ROOT / "build-support/measure-alloc.py"), COMPILERS[chapter]], check=True) results = read_results(args.log_dir) dynamic = read_dynamic(results) matrix = table(results, dynamic) (args.log_dir / "matrix.md").write_text(matrix + "\n", encoding="utf-8", newline="\n") if args.update_docs: - paths = [(ROOT / "docs/regalloc-spills.md", matrix)] - paths += [(ROOT / f"chapter{c}/README.md", table(results, dynamic, c)) for c in CHAPTERS] + # Preserve the dated pre-split measurements in the original READMEs. + paths = [(ROOT / "docs/appendices/current-spill-matrix.md", matrix)] # Validate all destinations before changing any document. for path, _ in paths: text = path.read_text(encoding="utf-8") |
