-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_metrics_table.py
More file actions
81 lines (65 loc) · 1.96 KB
/
generate_metrics_table.py
File metadata and controls
81 lines (65 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
"""
generate_metrics_table.py – Batch complexity profiler for all benchmark designs.
Walks the examples/ directory tree, finds every design_stats.json produced by
Yosys (via manage_formal.py or a manual 'yosys -s get_stats.ys' run), computes
structural metrics for each design, pretty-prints a table to stdout, and saves
the results to metrics_table.csv.
Usage:
python3 generate_metrics_table.py
Output:
metrics_table.csv (written to the current directory)
"""
import os
import csv
from extract_complexity_metrics import analyze_complexity
ROOT = "examples" # root directory to scan for design_stats.json files
results = []
for root, dirs, files in os.walk(ROOT):
if "design_stats.json" in files:
path = os.path.join(root, "design_stats.json")
design = os.path.basename(root)
metrics = analyze_complexity(path)
metrics["Design"] = design
results.append(metrics)
# Sort for deterministic order
results.sort(key=lambda x: x["Design"].lower())
header = [
"Design",
"D_A",
"D_M",
"W",
"W_norm",
"I_C",
"D_R",
"D_R_norm",
"CHI_ANALYTIC",
"CHI_NORM"
]
print("\nMetrics Table\n")
# Column formatting
row_format = "{:<18} {:>8} {:>8} {:>5} {:>8} {:>8} {:>10} {:>10} {:>15} {:>10}"
print(row_format.format(*header))
print("-" * 105)
for r in results:
print(row_format.format(
r["Design"],
r["D_A"],
r["D_M"],
r["W"],
r["W_norm"],
r["I_C"],
r["D_R"],
r["D_R_norm"],
r["CHI_ANALYTIC"],
r["CHI_NORM"]
))
# -------------------------
# Save CSV for analysis
# -------------------------
with open("metrics_table.csv", "w", newline="") as f:
writer = csv.DictWriter(f, fieldnames=header)
writer.writeheader()
for r in results:
writer.writerow({h: r[h] for h in header})
print("\nSaved metrics_table.csv")