diff --git a/nix/tools/loadtest.nix b/nix/tools/loadtest.nix index 7aa7c9f66..02390a7dc 100644 --- a/nix/tools/loadtest.nix +++ b/nix/tools/loadtest.nix @@ -240,7 +240,7 @@ let echo -e 'If a branch finishes its loadtest in less seconds than another branch, it will have blank cells for the missing seconds.\n' find loadtest -type f -iname '*.csv' \ - | sort -nr \ + | sort -m \ | ${mergeMonitorResults} ''; diff --git a/nix/tools/merge_monitor_result.py b/nix/tools/merge_monitor_result.py index 9fffb8408..2a6adcb76 100644 --- a/nix/tools/merge_monitor_result.py +++ b/nix/tools/merge_monitor_result.py @@ -3,7 +3,8 @@ import sys import pandas as pd KEY = "Elapsed seconds" - +BASE_METRICS = ["CPU (%)", "MEM (%)", "Real (MB)"] +branch_order = [] merged = None paths = [p.strip() for p in sys.stdin.read().split() if p.strip()] @@ -11,18 +12,33 @@ paths = [p.strip() for p in sys.stdin.read().split() if p.strip()] for csv_path in paths: # br is branch (variable shortened to pass linter) br = os.path.splitext(os.path.basename(csv_path))[0] + branch_order.append(br) df = pd.read_csv(csv_path) if KEY not in df.columns: sys.exit(f"{csv_path} is missing the {KEY} column") + for m in BASE_METRICS: + if m not in df.columns: + sys.exit(f"Error: '{csv_path}' missing required column '{m}'.") + # add branch marker to every metric column df = df.rename(columns={c: f"{c} [{br}]" for c in df.columns if c != KEY}) # outer join so missing rows appear merged = df if merged is None else merged.merge(df, on=KEY, how="outer") +# Re-order columns so related metrics are adjacent +ordered_cols = [KEY] +for metric in BASE_METRICS: + for br in branch_order: + col_name = f"{metric} [{br}]" + if col_name in merged.columns: + ordered_cols.append(col_name) + +merged = merged[ordered_cols] + # replace nan with empty string merged = merged.fillna("") merged.to_markdown(sys.stdout, index=False, tablefmt="github") diff --git a/nix/tools/monitor_pid.py b/nix/tools/monitor_pid.py index 24ba91477..07a175e95 100644 --- a/nix/tools/monitor_pid.py +++ b/nix/tools/monitor_pid.py @@ -5,6 +5,7 @@ import psutil import pandas as pd KEY = "Elapsed seconds" +BASE_METRICS = ["CPU (%)", "MEM (%)", "Real (MB)"] SAMPLE_INTERVAL_SECS = 1 if len(sys.argv) != 2 or not sys.argv[1].isdigit(): @@ -53,6 +54,6 @@ end = time.time() total_time = end - start print(f"Finished {pid} pid monitoring in {total_time:.3f}", file=sys.stderr) -cols = [KEY, "CPU (%)", "MEM (%)", "Real (MB)"] +cols = [KEY] + BASE_METRICS df = pd.DataFrame(records, columns=cols, dtype=str) df.to_csv(sys.stdout, index=False)