|
| 1 | +import signal |
| 2 | +import subprocess |
| 3 | +from multiprocessing import Pool |
| 4 | +from pathlib import Path |
| 5 | + |
| 6 | +""" |
| 7 | +Parallel backfilling helper for pyperformance runs on isolated CPUs. |
| 8 | +
|
| 9 | +Reads `sha=branch` pairs from backfill_shas.txt, invokes run-pyperformance.sh |
| 10 | +for each revision, and lets that wrapper pin the workload to an isolated CPU, |
| 11 | +materialize benchmark.conf, build CPython, and upload results to |
| 12 | +speed.python.org. Stdout/stderr for each revision are captured under |
| 13 | +output/<branch>-<sha>.(out|err). |
| 14 | +""" |
| 15 | + |
| 16 | + |
| 17 | +def get_revisions() -> tuple[str, str]: |
| 18 | + revisions = [] |
| 19 | + with open("backfill_shas.txt", "r") as f: |
| 20 | + for line in f: |
| 21 | + sha, branch = line.split("=") |
| 22 | + revisions.append((sha, branch.rstrip())) |
| 23 | + return revisions |
| 24 | + |
| 25 | + |
| 26 | +def run_pyperformance(revision): |
| 27 | + sha, branch = revision |
| 28 | + print(f"Running run-pyperformance.sh with sha: {sha}, branch: {branch}") |
| 29 | + output_dir = Path("output") |
| 30 | + output_dir.mkdir(parents=True, exist_ok=True) |
| 31 | + out_file = output_dir / f"{branch}-{sha}.out" |
| 32 | + err_file = output_dir / f"{branch}-{sha}.err" |
| 33 | + with open(out_file, "w") as output, open(err_file, "w") as error: |
| 34 | + subprocess.run( |
| 35 | + [ |
| 36 | + "./run-pyperformance.sh", |
| 37 | + "-x", |
| 38 | + "--", |
| 39 | + "compile", |
| 40 | + "benchmark.conf", |
| 41 | + sha, |
| 42 | + branch, |
| 43 | + ], |
| 44 | + stdout=output, |
| 45 | + stderr=error, |
| 46 | + ) |
| 47 | + |
| 48 | + |
| 49 | +if __name__ == "__main__": |
| 50 | + original_sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN) |
| 51 | + signal.signal(signal.SIGINT, original_sigint_handler) |
| 52 | + with Pool(8) as pool: |
| 53 | + res = pool.map_async(run_pyperformance, get_revisions()) |
| 54 | + # Without the timeout this blocking call ignores all signals. |
| 55 | + res.get(86400) |
0 commit comments