|
3 | 3 | import pandas as pd |
4 | 4 |
|
5 | 5 | KEY = "Elapsed seconds" |
6 | | - |
| 6 | +BASE_METRICS = ["CPU (%)", "MEM (%)", "Real (MB)"] |
| 7 | +branch_order = [] |
7 | 8 | merged = None |
8 | 9 |
|
9 | 10 | paths = [p.strip() for p in sys.stdin.read().split() if p.strip()] |
10 | 11 |
|
11 | 12 | for csv_path in paths: |
12 | 13 | # br is branch (variable shortened to pass linter) |
13 | 14 | br = os.path.splitext(os.path.basename(csv_path))[0] |
| 15 | + branch_order.append(br) |
14 | 16 |
|
15 | 17 | df = pd.read_csv(csv_path) |
16 | 18 |
|
17 | 19 | if KEY not in df.columns: |
18 | 20 | sys.exit(f"{csv_path} is missing the {KEY} column") |
19 | 21 |
|
| 22 | + for m in BASE_METRICS: |
| 23 | + if m not in df.columns: |
| 24 | + sys.exit(f"Error: '{csv_path}' missing required column '{m}'.") |
| 25 | + |
20 | 26 | # add branch marker to every metric column |
21 | 27 | df = df.rename(columns={c: f"{c} [{br}]" for c in df.columns if c != KEY}) |
22 | 28 |
|
23 | 29 | # outer join so missing rows appear |
24 | 30 | merged = df if merged is None else merged.merge(df, on=KEY, how="outer") |
25 | 31 |
|
| 32 | +# Re-order columns so related metrics are adjacent |
| 33 | +ordered_cols = [KEY] |
| 34 | +for metric in BASE_METRICS: |
| 35 | + for br in branch_order: |
| 36 | + col_name = f"{metric} [{br}]" |
| 37 | + if col_name in merged.columns: |
| 38 | + ordered_cols.append(col_name) |
| 39 | + |
| 40 | +merged = merged[ordered_cols] |
| 41 | + |
26 | 42 | # replace nan with empty string |
27 | 43 | merged = merged.fillna("") |
28 | 44 | merged.to_markdown(sys.stdout, index=False, tablefmt="github") |
0 commit comments