B3 post-run helpers: engine_state slicer + per-policy aggregator
scripts/slice_engine_state.py filters a shared engine_*.jsonl by a [t_start_unix, t_end_unix] window. Needed because the patched scheduler appends to one file per engine across the whole sweep; per-policy analysis requires the per-policy slice. scripts/b3_analyze.sh drives the slice + joined_analysis loop for every policy directory in a completed sweep, then aggregates one row per policy (latency percentiles, APC, interference_index, hotspot_index, reuse fractions, failure-cause counts) into b3_policy_comparison.json. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
46
scripts/slice_engine_state.py
Normal file
46
scripts/slice_engine_state.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""Slice shared engine_*.jsonl by a [t_start_unix, t_end_unix] window.
|
||||
|
||||
Used between B3 policy runs and the analyzer so each policy gets
|
||||
its own per-window engine_state directory.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main() -> None:
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument("--input-dir", type=Path, required=True)
|
||||
p.add_argument("--output-dir", type=Path, required=True)
|
||||
p.add_argument("--window", type=Path, required=True,
|
||||
help="run_window.json with t_start_unix / t_end_unix")
|
||||
args = p.parse_args()
|
||||
|
||||
window = json.loads(args.window.read_text())
|
||||
ts = float(window["t_start_unix"])
|
||||
te = float(window["t_end_unix"])
|
||||
|
||||
args.output_dir.mkdir(parents=True, exist_ok=True)
|
||||
print(f"window {ts:.3f} .. {te:.3f}")
|
||||
for src in sorted(args.input_dir.glob("engine_*.jsonl")):
|
||||
n_in = n_out = 0
|
||||
dst = args.output_dir / src.name
|
||||
with src.open() as fi, dst.open("w") as fo:
|
||||
for line in fi:
|
||||
n_in += 1
|
||||
try:
|
||||
r = json.loads(line)
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
t = r.get("t_unix", 0)
|
||||
if ts <= t <= te:
|
||||
fo.write(line)
|
||||
n_out += 1
|
||||
print(f" {src.name}: {n_out}/{n_in}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user