Skip to content

Commit 56abadd

Browse files
committed
Move plot python code to file
Signed-off-by: Antón Casas <antoncasas@eprosima.com>
1 parent 6fcaf37 commit 56abadd

File tree

2 files changed

+100
-65
lines changed

2 files changed

+100
-65
lines changed

.github/workflows/performance.yml

Lines changed: 40 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ jobs:
8484
name: performance-results
8585
path: results
8686

87-
- name: List files
88-
shell: bash
89-
run: |
90-
ls -l results
91-
9287
- name: Save results into memory
9388
shell: bash
9489
run: |
@@ -126,69 +121,49 @@ jobs:
126121
shell: bash
127122
run: |
128123
set -euxo pipefail
129-
python3 - <<'PY'
130-
import csv
131-
from pathlib import Path
132-
import matplotlib.pyplot as plt
133-
134-
ts_csv = Path("ci/metrics/complete_profile/complete_profile_timeseries.csv")
135-
out_png = Path("build/complete_profile_last30.png")
136-
out_png.parent.mkdir(parents=True, exist_ok=True)
137-
138-
if not ts_csv.exists():
139-
raise SystemExit("time-series CSV not found")
140-
141-
rows = []
142-
with ts_csv.open(newline="") as fh:
143-
reader = csv.DictReader(fh)
144-
header = reader.fieldnames or []
145-
for r in reader:
146-
rows.append(r)
147-
148-
if not rows:
149-
raise SystemExit("No rows in time-series CSV")
150-
151-
rows = rows[-30:] # last 30 runs
152-
153-
# Choose numeric columns (skip date, run, sha)
154-
skip = {"date","run","sha"}
155-
cols = [h for h in header if h not in skip]
156-
157-
x = range(1, len(rows)+1)
158-
dates = [r["date"] for r in rows]
159-
160-
plt.figure()
161-
for key in cols:
162-
try:
163-
ys = [int(r.get(key,0)) for r in rows]
164-
except Exception:
165-
continue
166-
plt.plot(x, ys, label=key)
167-
168-
plt.title("Complete Profile")
169-
plt.xlabel("Date")
170-
plt.ylabel("Bytes")
171-
step = max(1, len(dates)//8)
172-
shown = list(range(0, len(dates), step))
173-
plt.xticks([i+1 for i in shown], [dates[i] for i in shown], rotation=45, ha="right")
174-
175-
plt.legend()
176-
plt.tight_layout()
177-
plt.savefig(out_png)
178-
print(f"Wrote {out_png}")
179-
PY
124+
125+
LAST_N=52
126+
127+
python3 ci/metrics/generate_plot.py \
128+
--input ci/metrics/memory/complete_profile_timeseries.csv \
129+
--output plots/complete_profile_plot.png \
130+
--title "Complete Profile" \
131+
--ylabel "Bytes" \
132+
--last LAST_N
133+
python3 ci/metrics/generate_plot.py \
134+
--input ci/metrics/memory/core_profile_timeseries.csv \
135+
--output plots/core_profile_plot.png \
136+
--title "Core Profile" \
137+
--ylabel "Bytes" \
138+
--last LAST_N
139+
python3 ci/metrics/generate_plot.py \
140+
--input ci/metrics/memory/stack_timeseries.csv \
141+
--output plots/stack_plot.png \
142+
--title "Simple App Stack Usage" \
143+
--ylabel "Bytes" \
144+
--last LAST_N
145+
python3 ci/metrics/generate_plot.py \
146+
--input ci/metrics/memory/profiles_bss_timeseries.csv \
147+
--output plots/profiles_bss_plot.png \
148+
--title "Increase of .bss memory by enabling profiles" \
149+
--ylabel "Bytes" \
150+
--last LAST_N
151+
python3 ci/metrics/generate_plot.py \
152+
--input ci/metrics/memory/profiles_data_timeseries.csv \
153+
--output plots/profiles_data_plot.png \
154+
--title "Increase of .data memory by enabling profiles" \
155+
--ylabel "Bytes" \
156+
--last LAST_N
157+
python3 ci/metrics/generate_plot.py \
158+
--input ci/metrics/memory/profiles_text_timeseries.csv \
159+
--output plots/profiles_text_plot.png \
160+
--title "Increase of .text memory by enabling profiles" \
161+
--ylabel "Bytes" \
162+
--last LAST_N
180163
181164
- name: Upload plots
182165
uses: actions/upload-artifact@v4
183166
with:
184167
name: performance-plots
185-
path: build/*.png
168+
path: plots/*.png
186169
if-no-files-found: warn
187-
188-
- name: Add summary
189-
if: always()
190-
shell: bash
191-
run: |
192-
echo "## Complete Profile (last 30 runs)" >> "$GITHUB_STEP_SUMMARY"
193-
echo "" >> "$GITHUB_STEP_SUMMARY"
194-
echo "![Complete Profile](./build/complete_profile_last30.png)" >> "$GITHUB_STEP_SUMMARY"

ci/metrics/generate_plot.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python3
2+
import csv, sys, argparse
3+
from pathlib import Path
4+
import matplotlib.pyplot as plt
5+
6+
parser = argparse.ArgumentParser(description="Generate a plot from a time-series CSV")
7+
parser.add_argument("--input", required=True, help="Path to the cumulative time-series CSV")
8+
parser.add_argument("--output", required=True, help="Path to save the plot PNG")
9+
parser.add_argument("--title", default="", help="Title for the plot")
10+
parser.add_argument("--ylabel", default="", help="Y-axis label")
11+
parser.add_argument("--last", type=int, default=30, help="Number of last runs to plot")
12+
args = parser.parse_args()
13+
14+
ts_csv = Path(args.input)
15+
out_png = Path(args.output)
16+
17+
out_png.parent.mkdir(parents=True, exist_ok=True)
18+
19+
if not ts_csv.exists():
20+
sys.exit(f"{ts_csv} not found")
21+
22+
rows = []
23+
with ts_csv.open(newline="") as fh:
24+
reader = csv.DictReader(fh)
25+
header = reader.fieldnames or []
26+
for r in reader:
27+
rows.append(r)
28+
29+
if not rows:
30+
sys.exit("No rows in time-series CSV")
31+
32+
rows = rows[-(args.last):]
33+
34+
skip = {"date", "run", "sha"}
35+
cols = [h for h in header if h not in skip]
36+
37+
x = range(1, len(rows)+1)
38+
dates = [r["date"] for r in rows]
39+
40+
plt.figure()
41+
for key in cols:
42+
try:
43+
ys = [int(r.get(key, 0)) for r in rows]
44+
except Exception:
45+
continue
46+
plt.plot(x, ys, label=key)
47+
48+
plt.title(args.title)
49+
plt.xlabel("Date")
50+
plt.ylabel(args.ylabel)
51+
52+
# Thin x labels for readability
53+
step = max(1, len(dates)//8)
54+
shown = list(range(0, len(dates), step))
55+
plt.xticks([i+1 for i in shown], [dates[i] for i in shown], rotation=45, ha="right")
56+
57+
plt.legend()
58+
plt.tight_layout()
59+
plt.savefig(out_png)
60+
print(f"Wrote {out_png}")

0 commit comments

Comments
 (0)