#!/usr/bin/env python3 """One host's timings of two builds of the engine, side by side. before_after.py BEFORE.json AFTER.json OUT.json BEFORE and AFTER are tools/perf.py's output on one host with WAI_CROSS_SIMULATOR naming each build's driver, run one straight after the other. Standard library only. """ import json import sys def main(): before, after = (json.load(open(p)) for p in sys.argv[1:3]) # The host's identity, not its load at the moment each run began. same = lambda h: {k: v for k, v in h.items() if k != "load_average"} if same(before["host"]) != same(after["host"]) or before["repeat"] != after["repeat"]: sys.exit("before_after.py: two hosts, or two repeat counts: these timings do not compare") index = {(r["case"], r["engine"], r["threads"]): r for r in before["rows"]} rows = [] for r in after["rows"]: was = index.get((r["case"], r["engine"], r["threads"])) if was is not None: rows.append({"case": r["case"], "what": r["what"], "engine": r["engine"], "threads": r["threads"], "before": {k: v for k, v in was.items() if k not in ("case", "what", "engine", "threads")}, "after": {k: v for k, v in r.items() if k not in ("case", "what", "engine", "threads")}}) out = {"about": "One host's timings of two builds of the engine under test, one straight after the other: tools/perf.py run on each, tools/before_after.py putting them side by side.", "timers": after.get("timers"), "host": after["host"], "versions": after["versions"], "before": before["engine_under_test"], "after": after["engine_under_test"], "repeat": after["repeat"], "rows": rows} with open(sys.argv[3], "w") as f: json.dump(out, f, indent=1) f.write("\n") if __name__ == "__main__": main()