Skip to content

Commit

Permalink
(hw-results/tabular) fix: better parsing of herdtools-formatted logs
Browse files Browse the repository at this point in the history
  • Loading branch information
bensimner committed May 20, 2024
1 parent 89b321b commit 4112b0c
Showing 1 changed file with 43 additions and 19 deletions.
62 changes: 43 additions & 19 deletions hw-results/tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,28 +174,51 @@ def read_test_file_herd(device: Device, fname: str) -> LogFileResult:
# Observation MP+dmb+eret Never 0 500000
# Time MP+dmb+eret 3711.813

lineno = 0

def _next():
nonlocal lineno

while True:
n = next(f).strip()
try:
n = next(f).strip()
lineno += 1
except StopIteration:
return

if n.startswith("#"):
continue

# restrict down to header, histogram and observation lines
if n in ["Yes", "No", "Ok", "Witnesses"] or n.startswith("Time") or n.startswith("Hash") or n.startswith("Positive"):
continue

if not n:
continue

yield n

lines = _next()

def _read_test():
header = next(lines)
def _read_whole_test():
try:
header = next(lines)
except StopIteration:
# done
return None

if not header.startswith("Test "):
return False
raise SyntaxError("bad log: should start with `Test: `")

test_name = header.split()[1]

# "States N" or "Histogram (N states)"
states_header = next(lines)
states = int(states_header.partition(" ")[2])
if (states_header.startswith("States")):
states = int(states_header.partition(" ")[2])
else:
assert states_header.startswith("Histogram")
states = int(states_header.split()[1].lstrip("("))

recorded = []
for _ in range(states):
Expand All @@ -206,32 +229,33 @@ def _read_test():
rr = RunResult(regstates, count, False)
recorded.append(rr)

next(lines) # "Yes/No"
next(lines) # "Witnesses"
next(lines) # "Positive: N, Negative: M"

obs_header = next(lines)
obs = obs_header.split()
assert obs[0] == "Observation"
assert obs[1] == test_name

marks = int(obs[3])
return (test_name, recorded, marks)

def observations():
while True:
try:
t = _read_whole_test()
except Exception:
raise RuntimeError(f"in {fname} at line {lineno}: failed to parse log")

if not t:
return

yield t

for (test_name, recorded, marks) in observations():
h = Hist(test_name, recorded, marks)

lfr.results += [h]
if test_name not in lfr.total:
lfr.total[test_name] = Hist(test_name, [], 0)
lfr.total[test_name].update(h)

next(lines) # Times
return True

while True:
try:
_read_test()
except RuntimeError:
break

return lfr


Expand Down

0 comments on commit 4112b0c

Please sign in to comment.