Files
leleka/scripts/perf3/cmp_rhash.py
T

37 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""Compare the PREFILL-R hash sequences (final residual R of every prefill chunk) of the arms of a replay job (p34).
usage: cmp_rhash.py FULL_LOG [ARM_A ARM_B]
Arms are split by `REPLAY-ARM start label=` lines; every `PREFILL-R first=F rows=N fnv1a64=H` line is one chunk. Prints the chunk count per arm and whether the
(first, rows, hash) sequences of ARM_A and ARM_B (default: the first two arms) are identical; the first differing chunk is listed. Exit code 1 on a difference.
"""
import re
import sys
log = sys.argv[1]
arms = {}
order = []
cur = None
for line in open(log, errors="replace"):
m = re.search(r"REPLAY-ARM start label=(\S+)", line)
if m:
cur = m[1]
arms[cur] = []
order.append(cur)
continue
m = re.search(r"PREFILL-R first=(\d+) rows=(\d+) fnv1a64=(\w+)", line)
if m and cur is not None:
arms[cur].append((int(m[1]), int(m[2]), m[3]))
a, b = (sys.argv[2], sys.argv[3]) if len(sys.argv) >= 4 else (order[0], order[1])
for k in order:
print(f"arm {k}: {len(arms[k])} chunks")
same = arms[a] == arms[b] and len(arms[a]) > 0
print(f"{a} vs {b}: {'IDENTICAL' if same else 'DIFFERENT'} ({len(arms[a])} / {len(arms[b])} chunks)")
if not same:
for i, (x, y) in enumerate(zip(arms[a], arms[b])):
if x != y:
print(f"first difference at chunk {i}: {x} vs {y}")
break
sys.exit(1)