Datasets:
Download scripts/t2b-bench/t2prof.py from DrumsRL/drums-benchmarks: direct link, hf CLI and curl.
- Browser
- Download file 6.25 kB
-
https://huggingface.co/datasets/DrumsRL/drums-benchmarks/resolve/main/scripts/t2b-bench/t2prof.py
- Command line
-
hf download hf://datasets/DrumsRL/drums-benchmarks/scripts/t2b-bench/t2prof.py
-
curl -L -o t2prof.py https://huggingface.co/datasets/DrumsRL/drums-benchmarks/resolve/main/scripts/t2b-bench/t2prof.py
6.25 kB
| """T2 profile/benchmark driver: a live desktop with Chrome AND LibreOffice Calc open, mid-task (typed state in both), | |
| then repeated fork(N) of that parent (children closed after each), and resets of a child to its clean state. | |
| Writes one JSON line per measured operation (raw, nothing aggregated) to --out. | |
| python3 t2prof.py --token-file /etc/drums/token --forks 10 --n 4 --resets 10 --out raw.jsonl [--label old] | |
| """ | |
| import argparse, json, os, sys, time | |
| sys.path.insert(0, os.environ.get("DRUMS_SDK", "/opt/drums/src/drumsd/python")) | |
| import drums | |
| CHROME = "2ad9387a-65d8-4e33-ad5b-7580065a27ca" | |
| def jl(f, rec): | |
| f.write(json.dumps(rec, default=str) + "\n"); f.flush() | |
| def build_parent(c, log): | |
| t0 = time.monotonic() | |
| env = c.create(image="osworld-ubuntu", task=CHROME) | |
| jl(log, {"kind": "create", "env": env.id, "s": round(time.monotonic() - t0, 3), "timings": env.record.get("timings")}) | |
| # LibreOffice Calc next to Chrome, typed cells in Calc, typed omnibox text in a new Chrome tab | |
| env.step({"type": "launch", "command": ["libreoffice", "--calc", "--norestore"], "shell": False}) | |
| wait = ("import subprocess, time\n" | |
| "for i in range(120):\n" | |
| " if 'LibreOffice Calc' in subprocess.run(['wmctrl', '-l'], capture_output=True, text=True).stdout: break\n" | |
| " time.sleep(0.5)\n" | |
| "time.sleep(2)\n") | |
| env.step({"type": "execute", "command": ["python3", "-c", wait], "shell": False}) | |
| env.step("pyautogui.write('Revenue', interval=0.02); pyautogui.press('tab'); pyautogui.write('1234', interval=0.02); pyautogui.press('enter'); time.sleep(0.5)") | |
| env.step("pyautogui.write('=B1*2', interval=0.02); pyautogui.press('enter'); time.sleep(0.5)") | |
| env.step({"type": "execute", "command": ["wmctrl", "-a", "Google Chrome"], "shell": False}) | |
| env.step("pyautogui.hotkey('ctrl', 't'); time.sleep(1); pyautogui.write('drums mid task', interval=0.03); time.sleep(0.5)") | |
| ps = env.guest().execute(["sh", "-c", "ps -e -o comm= | sort | uniq -c | sort -rn | head -40; ps -e --no-headers | wc -l; ps -eL --no-headers | wc -l"], shell=False) | |
| jl(log, {"kind": "parent_ready", "env": env.id, "procs": ps}) | |
| return env | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--url", default="http://127.0.0.1:7070") | |
| ap.add_argument("--token-file", default="/etc/drums/token") | |
| ap.add_argument("--forks", type=int, default=10) | |
| ap.add_argument("--n", type=int, default=4) | |
| ap.add_argument("--resets", type=int, default=10) | |
| ap.add_argument("--gap", type=float, default=2.0, help="seconds between the last action and the fork (the policy's think time)") | |
| ap.add_argument("--label", default="") | |
| ap.add_argument("--prefork", action="store_true", help="T2b arm W1p: env.prefork(n) right after the action, then the think time, then fork(n)") | |
| ap.add_argument("--skip-forks", action="store_true") | |
| ap.add_argument("--out", required=True) | |
| a = ap.parse_args() | |
| c = drums.connect(a.url, open(a.token_file).read().strip()) | |
| log = open(a.out, "a") | |
| h = c.health() | |
| jl(log, {"kind": "health", "label": a.label, "version": h.get("version"), "criu": h.get("criu"), "epoch": time.time()}) | |
| env = build_parent(c, log) | |
| kids_keep = None | |
| for i in range(0 if a.skip_forks else a.forks): | |
| # one small action between forks: the parent keeps moving (mid-task), then the policy's think time | |
| env.step(f"pyautogui.write('{i}', interval=0.02); time.sleep(0.2)") | |
| pf = None | |
| if a.prefork: | |
| tp = time.monotonic() | |
| pf = env.prefork(a.n, keep_state=False) | |
| pf = {"reply": pf, "call_s": round(time.monotonic() - tp, 4)} | |
| time.sleep(a.gap) | |
| t0 = time.monotonic(); err = None; kids = [] | |
| try: | |
| kids = env.fork(a.n, keep_state=False) | |
| except drums.DrumsError as e: | |
| err = f"{type(e).__name__}: {e}" | |
| wall = round(time.monotonic() - t0, 4) | |
| lf = env.last_fork or {} | |
| rec = {"kind": "fork", "i": i, "n": a.n, "label": a.label, "wall_s": wall, "error": err, | |
| "server": {k: lf.get(k) for k in ("capture_s", "children_ready_s", "seconds", "prefork")}, "prefork_call": pf, | |
| "quiescence": ((lf.get("checkpoint") or {}).get("quiescence")), | |
| "children": [{"id": k.id, "timings": k.record.get("timings"), "gates": k.record.get("gates"), "cost": k.record.get("cost")} for k in kids]} | |
| # validity: every child's deferred alive gate must resolve valid | |
| vv = [] | |
| for k in kids: | |
| try: | |
| k.wait_valid(timeout=60); vv.append({"id": k.id, "valid": True}) | |
| except drums.DrumsError as e: | |
| vv.append({"id": k.id, "valid": False, "why": str(e)[:400], "record": k.refresh()}) | |
| rec["validity"] = vv | |
| jl(log, rec) | |
| if i == a.forks - 1 and kids: | |
| kids_keep = kids[0] | |
| for k in kids[1:]: k.close() | |
| else: | |
| for k in kids: k.close() | |
| if kids_keep is not None: | |
| kids_keep.close() | |
| # clean reset: an env made from the clean image with the task, dirtied by one action, reset back, repeated | |
| if a.resets: | |
| r0 = time.monotonic() | |
| renv = c.create(image="osworld-ubuntu", task=CHROME) | |
| jl(log, {"kind": "create", "env": renv.id, "s": round(time.monotonic() - r0, 3), "timings": renv.record.get("timings"), "for": "reset"}) | |
| for j in range(a.resets): | |
| renv.step("pyautogui.hotkey('ctrl', 't'); time.sleep(0.5); pyautogui.write('dirty', interval=0.02)") | |
| t0 = time.monotonic(); err = None | |
| try: | |
| renv.reset() | |
| except drums.DrumsError as e: | |
| err = f"{type(e).__name__}: {e}" | |
| wall = round(time.monotonic() - t0, 4) | |
| v = None | |
| try: | |
| renv.wait_valid(timeout=60); v = True | |
| except drums.DrumsError as e: | |
| v = False | |
| jl(log, {"kind": "reset", "j": j, "label": a.label, "wall_s": wall, "error": err, "valid": v, "timings": renv.record.get("timings"), "gates": renv.record.get("gates")}) | |
| renv.close() | |
| env.close() | |
| if __name__ == "__main__": | |
| main() | |