cc11082ea7
CI / lint-test-build (push) Failing after 19s
- Added synthetic latency profiler scenarios and CLI scripts for baseline generation and regression checks. - Introduced latency baseline and threshold artifacts for CI enforcement. - Enhanced CI workflow with latency guardrail checks. - Updated documentation to include latency profiling commands and performance metrics. - Added unit tests for latency guardrail evaluation.
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from arbitrade.perf.guardrails import evaluate_guardrails
|
|
from arbitrade.perf.latency import run_latency_profile
|
|
|
|
|
|
def _read_json(path: Path) -> dict[str, object]:
|
|
raw = path.read_text(encoding="utf-8")
|
|
parsed = json.loads(raw)
|
|
if not isinstance(parsed, dict):
|
|
raise ValueError(f"Expected object JSON at {path}")
|
|
return {str(k): parsed[k] for k in parsed}
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(
|
|
description="Check latency profile against baseline thresholds."
|
|
)
|
|
parser.add_argument("--baseline", type=Path, required=True)
|
|
parser.add_argument("--thresholds", type=Path, required=True)
|
|
parser.add_argument("--iterations", type=int, default=600)
|
|
parser.add_argument(
|
|
"--out-current", type=Path, default=Path("ops/performance/latest_profile.json")
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
baseline = _read_json(args.baseline)
|
|
thresholds = _read_json(args.thresholds)
|
|
current = run_latency_profile(iterations=args.iterations)
|
|
|
|
args.out_current.parent.mkdir(parents=True, exist_ok=True)
|
|
args.out_current.write_text(json.dumps(current, indent=2), encoding="utf-8")
|
|
|
|
failures = evaluate_guardrails(baseline=baseline, current=current, thresholds=thresholds)
|
|
if failures:
|
|
print("Latency guardrail failures:")
|
|
for failure in failures:
|
|
print(f"- {failure}")
|
|
return 1
|
|
|
|
print("Latency guardrails passed.")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|