File size: 2,518 Bytes
7c188b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""Live monitor for a MAUI-Bench run.

  python src/monitor.py --run-id run_YYYYMMDD_HHMMSS [--watch 15]

Prints completion percentage, throughput, ETA, per-topology and per-model
progress, error counts, and a rolling view of the last failures.
"""
from __future__ import annotations

import argparse
import json
import os
import time
from collections import Counter


def snapshot(run_dir: str) -> None:
    prog_path = os.path.join(run_dir, "progress.json")
    rec_path = os.path.join(run_dir, "records.jsonl")
    if os.path.exists(prog_path):
        with open(prog_path) as f:
            p = json.load(f)
        print(f"progress: {p['done']}/{p['total']} ({p['pct']}%)  "
              f"rate {p['cells_per_s']}/s  eta {p['eta_s']/60:.1f} min")
    if not os.path.exists(rec_path):
        print("no records yet")
        return
    by_topo, by_model, by_cond = Counter(), Counter(), Counter()
    errors, parse_fail, n = [], 0, 0
    with open(rec_path) as f:
        for line in f:
            try:
                r = json.loads(line)
            except Exception:
                continue
            n += 1
            by_topo[r.get("topology", "?")] += 1
            by_model[r.get("model", "?")] += 1
            by_cond[r.get("condition", "?")] += 1
            if r.get("key") == "ERR" or r.get("error"):
                errors.append(r)
            if r.get("parsed_ok") is False:
                parse_fail += 1
    print(f"records: {n}   harness errors: {len(errors)}   "
          f"parse failures: {parse_fail} ({100*parse_fail/max(n,1):.1f}%)")
    print("by topology:", dict(by_topo))
    print("by condition:", dict(by_cond))
    print("by model (top 8):", dict(by_model.most_common(8)))
    for e in errors[-3:]:
        print("  last error:", str(e.get("error", ""))[:160])


def main() -> None:
    ap = argparse.ArgumentParser()
    ap.add_argument("--run-id", required=True)
    ap.add_argument("--results-dir", default="results")
    ap.add_argument("--watch", type=int, default=0,
                    help="refresh interval in seconds (0 = print once)")
    args = ap.parse_args()
    run_dir = os.path.join(args.results_dir, args.run_id)
    while True:
        os.system("clear" if os.name != "nt" else "cls") if args.watch else None
        print(f"=== MAUI-Bench monitor: {args.run_id} "
              f"({time.strftime('%H:%M:%S')}) ===")
        snapshot(run_dir)
        if not args.watch:
            break
        time.sleep(args.watch)


if __name__ == "__main__":
    main()