|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import re |
| 3 | +import os |
| 4 | +import glob |
| 5 | + |
| 6 | +timing_data = [] |
| 7 | + |
| 8 | +for result_file in sorted(glob.glob("*/result.txt")): |
| 9 | + test_name = os.path.dirname(result_file) |
| 10 | + expect_file = result_file.replace("result.txt", "expect.txt") |
| 11 | + |
| 12 | + if not os.path.exists(expect_file): |
| 13 | + continue |
| 14 | + |
| 15 | + with open(result_file) as f: |
| 16 | + result_content = f.read() |
| 17 | + with open(expect_file) as f: |
| 18 | + expect_content = f.read() |
| 19 | + |
| 20 | + for line in result_content.split("\n"): |
| 21 | + if "Step" in line and "Max High=" in line: |
| 22 | + m = re.search(r"(Step\w+):.*Max High=(\d+)us Total High=(\d+)us", line) |
| 23 | + if m: |
| 24 | + step_name = m.group(1) |
| 25 | + max_high = int(m.group(2)) |
| 26 | + total_high = int(m.group(3)) |
| 27 | + |
| 28 | + exp_line = [ |
| 29 | + l |
| 30 | + for l in expect_content.split("\n") |
| 31 | + if step_name in l and "Max High" in l |
| 32 | + ] |
| 33 | + if exp_line: |
| 34 | + em = re.search( |
| 35 | + r"Max High<=(\d+)us Total High<=(\d+)us", exp_line[0] |
| 36 | + ) |
| 37 | + if em: |
| 38 | + exp_max = int(em.group(1)) |
| 39 | + exp_total = int(em.group(2)) |
| 40 | + timing_data.append( |
| 41 | + { |
| 42 | + "test": test_name, |
| 43 | + "metric": f"{step_name}_Max_High_us", |
| 44 | + "result": max_high, |
| 45 | + "expect": exp_max, |
| 46 | + } |
| 47 | + ) |
| 48 | + timing_data.append( |
| 49 | + { |
| 50 | + "test": test_name, |
| 51 | + "metric": f"{step_name}_Total_High_us", |
| 52 | + "result": total_high, |
| 53 | + "expect": exp_total, |
| 54 | + } |
| 55 | + ) |
| 56 | + |
| 57 | + elif "Time in" in line and "max=" in line: |
| 58 | + m = re.search(r"Time in (\w+)\s+max=(\d+)\s*us,\s*total=(\d+)", line) |
| 59 | + if m: |
| 60 | + isr_name = m.group(1) |
| 61 | + max_val = int(m.group(2)) |
| 62 | + total_val = int(m.group(3)) |
| 63 | + |
| 64 | + exp_line = [ |
| 65 | + l for l in expect_content.split("\n") if f"Time in {isr_name}" in l |
| 66 | + ] |
| 67 | + if exp_line: |
| 68 | + em = re.search(r"max<=(\d+)\s*us,\s*total<=(\d+)", exp_line[0]) |
| 69 | + if em: |
| 70 | + exp_max = int(em.group(1)) |
| 71 | + exp_total = int(em.group(2)) |
| 72 | + timing_data.append( |
| 73 | + { |
| 74 | + "test": test_name, |
| 75 | + "metric": f"{isr_name}_Max_us", |
| 76 | + "result": max_val, |
| 77 | + "expect": exp_max, |
| 78 | + } |
| 79 | + ) |
| 80 | + timing_data.append( |
| 81 | + { |
| 82 | + "test": test_name, |
| 83 | + "metric": f"{isr_name}_Total_us", |
| 84 | + "result": total_val, |
| 85 | + "expect": exp_total, |
| 86 | + } |
| 87 | + ) |
| 88 | + |
| 89 | +seen = set() |
| 90 | +unique_data = [] |
| 91 | +for d in timing_data: |
| 92 | + key = (d["test"], d["metric"]) |
| 93 | + if key not in seen: |
| 94 | + seen.add(key) |
| 95 | + unique_data.append(d) |
| 96 | + |
| 97 | +print("=" * 90) |
| 98 | +print(f"{'Test':<30} {'Metric':<22} {'Result':>10} {'Expect':>10} {'Util%':>8}") |
| 99 | +print("=" * 90) |
| 100 | + |
| 101 | +for d in sorted(unique_data, key=lambda x: (x["test"], x["metric"])): |
| 102 | + util = (d["result"] / d["expect"]) * 100 if d["expect"] > 0 else 0 |
| 103 | + status = "OK" if d["result"] <= d["expect"] else "FAIL" |
| 104 | + print( |
| 105 | + f"{d['test']:<30} {d['metric']:<22} {d['result']:>10} {d['expect']:>10} {util:>7.1f}% {status}" |
| 106 | + ) |
| 107 | + |
| 108 | +with open("timing_comparison.dat", "w") as f: |
| 109 | + f.write("# Test Metric Result Expect Utilization\n") |
| 110 | + for d in sorted(unique_data, key=lambda x: (x["test"], x["metric"])): |
| 111 | + util = (d["result"] / d["expect"]) * 100 if d["expect"] > 0 else 0 |
| 112 | + f.write( |
| 113 | + f'"{d["test"]}" "{d["metric"]}" {d["result"]} {d["expect"]} {util:.1f}\n' |
| 114 | + ) |
| 115 | + |
| 116 | +print("\nData written to timing_comparison.dat") |
0 commit comments