diff options
Diffstat (limited to 'tools/test-surface.py')
| -rw-r--r-- | tools/test-surface.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tools/test-surface.py b/tools/test-surface.py index 40385ad..7a89069 100644 --- a/tools/test-surface.py +++ b/tools/test-surface.py @@ -279,12 +279,34 @@ if __name__ == "__main__": ap = argparse.ArgumentParser() ap.add_argument("--json", action="store_true") ap.add_argument("--write", action="store_true") + ap.add_argument("--write-budget", metavar="FILE", + help="re-record the `test_surface` section of the budget file") a = ap.parse_args() rows = analyse() if a.json: counts = collections.Counter(r["disp"] for r in rows) counts["gate_pending"] = sum(1 for r in rows if r["disp"] == "gate" and not r["gated"]) + counts["ungated"] = sum(1 for r in rows if not r["gated"]) + counts["total"] = len(rows) print(json.dumps({"rows": rows, "counts": counts}, indent=1)) + elif a.write_budget: + rows = analyse() + counts = collections.Counter(r["disp"] for r in rows) + counts["gate_pending"] = sum(1 for r in rows if r["disp"] == "gate" and not r["gated"]) + counts["ungated"] = sum(1 for r in rows if not r["gated"]) + counts["total"] = len(rows) + path = a.write_budget + if not os.path.isabs(path): + path = os.path.join(ROOT, path) + budget = json.load(open(path)) + budget["test_surface"] = {k: counts[k] for k in + ("gate", "gate_pending", "move-test", "narrow", + "residue", "already-gated", "total", "ungated") + if counts[k]} + with open(path, "w") as handle: + json.dump(budget, handle, indent=2, sort_keys=True) + handle.write("\n") + print("wrote", os.path.relpath(path, ROOT), json.dumps(budget["test_surface"], sort_keys=True)) elif a.write: open(DOC, "w").write(render(rows)) print("wrote", os.path.relpath(DOC, ROOT)) |
