Skip to content

Commit 7118ee5

Browse files
committed
add timing plot to extras/tests/simavr_based
1 parent 207bdaf commit 7118ee5

9 files changed

Lines changed: 252 additions & 1 deletion

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
*.swp
22
*.o
3-
*.py
43
.pio
54
.dir
65
.tested

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pre-0.34.1:
22
- add memory report script
33
- rename old pmf/PMF to log2/LOG2 representation and define type `log2_value_t`
4+
- add timing plot `to extras/tests/simavr_based`
45

56
0.34.0:
67
- Major internal refactoring: reorganize code into subdirectories

extras/tests/simavr_based/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,11 @@ clean:
6868
find . -type l -delete
6969
find . -type d -empty -delete
7070
rm -f .links .makefiles
71+
rm -f timing_analysis/scatter_*.dat timing_analysis/timing_*.csv timing_analysis/timing_gnuplot.dat timing_analysis/timing_comparison.png
72+
73+
timing: timing_analysis/summarize_timing.py
74+
cd timing_analysis && python3 summarize_timing.py
75+
76+
timing-plot: timing timing_analysis/plot_timing.gp
77+
cd timing_analysis && gnuplot plot_timing.gp 2>/dev/null || echo "gnuplot not available"
7178

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
set terminal pngcairo size 1200,500 enhanced font 'Arial,10'
2+
set output 'timing_comparison.png'
3+
4+
set multiplot layout 1,2
5+
6+
set title "Max High Time: Actual vs Expected" font ',12'
7+
set xlabel "Expected (us)" font ',10'
8+
set ylabel "Actual (us)" font ',10'
9+
set grid
10+
set key bottom right
11+
set size ratio 1
12+
13+
max_val = 45
14+
set xrange [0:max_val]
15+
set yrange [0:max_val]
16+
17+
plot [0:max_val] x with lines lc rgb 'red' lw 1 title 'y=x (limit)', \
18+
'scatter_max_high.dat' using 1:2 with points pt 7 ps 1.5 lc rgb '#4CAF50' title 'Actual', \
19+
'' using 1:2:3 with labels offset 1,0.5 font ',7' left notitle
20+
21+
set title "Total High Time: Actual vs Expected" font ',12'
22+
set xlabel "Expected (us)" font ',10'
23+
set ylabel "Actual (us)" font ',10'
24+
set size ratio 1
25+
26+
max_val = 550000
27+
set xrange [0:max_val]
28+
set yrange [0:max_val]
29+
30+
plot [0:max_val] x with lines lc rgb 'red' lw 1 title 'y=x (limit)', \
31+
'scatter_total.dat' using 1:2 with points pt 7 ps 1.5 lc rgb '#2196F3' title 'Actual', \
32+
'' using 1:2:3 with labels offset 1,0.5 font ',7' left notitle
33+
34+
unset multiplot
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# expected actual label
2+
35 29 "2560:StepA"
3+
35 30 "2560:StepB"
4+
40 34 "2560:StepC"
5+
20 13 "328p:StepA"
6+
25 18 "328p:StepB"
7+
15 10 "328p_37k:StepA"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# expected actual label
2+
350000 314627 "2560:StepA"
3+
400000 360837 "2560:StepB"
4+
510000 463190 "2560:StepC"
5+
4500 4196 "328p:StepA"
6+
5300 5005 "328p:StepB"
7+
4200 3934 "328p_37k:StepA"
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python3
2+
import re
3+
import os
4+
import glob
5+
6+
max_high_data = []
7+
total_data = []
8+
9+
for result_file in sorted(glob.glob("../*/result.txt")):
10+
test_name = os.path.basename(os.path.dirname(result_file))
11+
expect_file = result_file.replace("result.txt", "expect.txt")
12+
13+
if not os.path.exists(expect_file):
14+
continue
15+
16+
with open(result_file) as f:
17+
result_content = f.read()
18+
with open(expect_file) as f:
19+
expect_content = f.read()
20+
21+
for line in result_content.split("\n"):
22+
if "Step" in line and "Max High=" in line:
23+
m = re.search(r"(Step\w+):.*Max High=(\d+)us Total High=(\d+)us", line)
24+
if m:
25+
step_name = m.group(1)
26+
max_high = int(m.group(2))
27+
total_high = int(m.group(3))
28+
29+
exp_line = [
30+
l
31+
for l in expect_content.split("\n")
32+
if step_name in l and "Max High" in l
33+
]
34+
if exp_line:
35+
em = re.search(
36+
r"Max High<=(\d+)us Total High<=(\d+)us", exp_line[0]
37+
)
38+
if em:
39+
exp_max = int(em.group(1))
40+
exp_total = int(em.group(2))
41+
max_high_data.append(
42+
{
43+
"test": test_name.replace("test_sd_04_timing_", ""),
44+
"step": step_name,
45+
"result": max_high,
46+
"expect": exp_max,
47+
}
48+
)
49+
total_data.append(
50+
{
51+
"test": test_name.replace("test_sd_04_timing_", ""),
52+
"step": step_name,
53+
"result": total_high,
54+
"expect": exp_total,
55+
}
56+
)
57+
58+
print("\n### Max High Time (us): Actual vs Expected\n")
59+
print("| Test | Step | Actual | Expected |")
60+
print("|------|------|--------|----------|")
61+
for d in sorted(max_high_data, key=lambda x: (x["test"], x["step"])):
62+
print(f"| {d['test']} | {d['step']} | {d['result']} | {d['expect']} |")
63+
64+
print("\n### Total High Time (us): Actual vs Expected\n")
65+
print("| Test | Step | Actual | Expected |")
66+
print("|------|------|--------|----------|")
67+
for d in sorted(total_data, key=lambda x: (x["test"], x["step"])):
68+
print(f"| {d['test']} | {d['step']} | {d['result']} | {d['expect']} |")
69+
70+
with open("scatter_max_high.dat", "w") as f:
71+
f.write("# expected actual label\n")
72+
for d in max_high_data:
73+
f.write(f'{d["expect"]} {d["result"]} "{d["test"]}:{d["step"]}"\n')
74+
75+
with open("scatter_total.dat", "w") as f:
76+
f.write("# expected actual label\n")
77+
for d in total_data:
78+
f.write(f'{d["expect"]} {d["result"]} "{d["test"]}:{d["step"]}"\n')
79+
80+
print("\n\nData files: scatter_max_high.dat, scatter_total.dat")
46.1 KB
Loading

0 commit comments

Comments
 (0)