Commit 0ec99414 authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

[tmp] add script to parse log folders

parent c525f093
Loading
Loading
Loading
Loading
Loading

scripts/run_diff.py

0 → 100644
+66 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
from diff_complexity import (
    log2df,
    diff_wmops,
    diff_mem,
)
from pathlib import Path
import pandas as pd
from tqdm import tqdm
import numpy as np

REF_LOGDIR = Path("float_detail_run_21_1_2025/output/logs")
CUT_LOGDIR = Path("basop_detail_run_21_1_2025/output/logs")

ref_logfiles = sorted(
    f
    for f in REF_LOGDIR.glob("*.txt")
    if not f.name.endswith("pcm.txt") and "dec" in f.stem
    # and "ltv48_STEREO" in f.stem
)
cut_logfiles = sorted(
    f
    for f in CUT_LOGDIR.glob("*.txt")
    if not f.name.endswith("pcm.txt") and "dec" in f.stem
    # and "ltv48_STEREO" in f.stem
)

unique = set(f.name for f in ref_logfiles).difference(f.name for f in cut_logfiles)
if unique:
    raise FileNotFoundError(
        f"One or more files were not found in either directory {unique}"
    )

records = []
crashes = []
for ref, cut in tqdm(zip(ref_logfiles, cut_logfiles), total=len(ref_logfiles)):
    # parse logfiles
    try:
        ref_wmops, ref_mem = log2df(ref)
    except ValueError:
        crashes.append(str(ref))
        continue
    try:
        cut_wmops, cut_mem = log2df(cut)
    except ValueError:
        crashes.append(str(cut))
        continue

    # get the diff for wmops and memory
    wmops = diff_wmops(ref_wmops, cut_wmops)
    mem = diff_mem(ref_mem, cut_mem)

    # only extract the difference column
    diff = pd.DataFrame(pd.concat([wmops, mem])["CUT - BSL"]).T
    diff.rename({"CUT - BSL": "Values"}, inplace=True, axis=1)

    diff.insert(0, "Name", ref.stem)
    records.append(diff)

df = pd.DataFrame(np.squeeze(records), columns=diff.columns)
df.set_index("Name", inplace=True)
df.sort_values("WMOPs max", inplace=True, ascending=False)
df.to_csv("all_diff.csv", float_format="%.3f")

with open("crashes.log", "w") as f:
    [print(c, file=f) for c in crashes]