feat(scripts.track1):lab3 track1 sweep and csv collectors
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Собирает k6 summaries из серии трека 1 в плоскую CSV.
|
||||
|
||||
Использование:
|
||||
python3 scripts/track1-csv.py evidence/track1/series-a > evidence/track1/series-a.csv
|
||||
"""
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def parse_name(stem: str) -> tuple[str, int]:
|
||||
"""rep2-cpu0.5-mem256M-run3-k6 -> ('rep2-cpu0.5-mem256M', 3)"""
|
||||
m = re.match(r"(.+)-run(\d+)-k6$", stem)
|
||||
if not m:
|
||||
return stem, 0
|
||||
return m.group(1), int(m.group(2))
|
||||
|
||||
|
||||
FIELDS = [
|
||||
("http_reqs", "rate"),
|
||||
("http_req_failed", "rate"),
|
||||
("write_errors", "rate"),
|
||||
("write_total", "count"),
|
||||
("write_latency_ms", "avg"),
|
||||
("write_latency_ms", "p(90)"),
|
||||
("write_latency_ms", "p(95)"),
|
||||
("write_latency_ms", "max"),
|
||||
]
|
||||
|
||||
|
||||
def main() -> int:
|
||||
if len(sys.argv) < 2:
|
||||
print("usage: track1-csv.py <directory>", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
d = Path(sys.argv[1])
|
||||
if not d.is_dir():
|
||||
print(f"not a directory: {d}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
print("config,run,metric,value")
|
||||
for path in sorted(d.glob("*-k6.json")):
|
||||
config, run = parse_name(path.stem)
|
||||
try:
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
except (OSError, json.JSONDecodeError) as exc:
|
||||
print(f"# skip {path}: {exc}", file=sys.stderr)
|
||||
continue
|
||||
metrics = data.get("metrics", {})
|
||||
for metric, key in FIELDS:
|
||||
entry = metrics.get(metric)
|
||||
if not entry:
|
||||
continue
|
||||
values = entry.get("values", entry)
|
||||
value = values.get(key)
|
||||
if value is None:
|
||||
continue
|
||||
print(f"{config},{run},{metric}.{key},{value}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user