Skip to content

Commit dec7fb2

Browse files
committed
move to developer-content
1 parent 25d76c3 commit dec7fb2

16 files changed

+623566
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import csv
2+
import subprocess
3+
import time
4+
5+
import psutil
6+
7+
DIRS = ["CTD", "plus_CTD_BGC", "plus_DRIFTER", "plus_ARGO", "plus_UNDERWAY"]
8+
RESULTS_FILE = "performance_results.csv"
9+
10+
# Write header once at the start
11+
with open(RESULTS_FILE, "w", newline="") as csvfile:
12+
writer = csv.writer(csvfile)
13+
writer.writerow(["Directory", "Time (s)", "Peak RAM (MB)"])
14+
15+
16+
def run_and_trace(cmd):
17+
start_time = time.time()
18+
process = subprocess.Popen(cmd, shell=True)
19+
proc = psutil.Process(process.pid)
20+
peak_mem = 0
21+
22+
while process.poll() is None:
23+
try:
24+
mem = proc.memory_info().rss / (1024 * 1024) # MB
25+
if mem > peak_mem:
26+
peak_mem = mem
27+
except psutil.NoSuchProcess:
28+
break
29+
time.sleep(0.1)
30+
31+
end_time = time.time()
32+
return end_time - start_time, peak_mem
33+
34+
35+
for dir_name in DIRS:
36+
cmd = f"virtualship run ../{dir_name}"
37+
print(f"Running: {cmd}")
38+
elapsed, peak_mem = run_and_trace(cmd)
39+
# Write result after each iteration
40+
with open(RESULTS_FILE, "a", newline="") as csvfile:
41+
writer = csv.writer(csvfile)
42+
writer.writerow([dir_name, f"{elapsed:.2f}", f"{peak_mem:.2f}"])
43+
44+
print(f"\nResults written to {RESULTS_FILE}")
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import csv
2+
import subprocess
3+
import time
4+
5+
import psutil
6+
7+
DIRS = ["CTD", "plus_CTD_BGC", "plus_DRIFTER", "plus_ARGO", "plus_UNDERWAY"]
8+
RESULTS_FILE = "performance_results_fromdata.csv"
9+
10+
# Write header once at the start
11+
with open(RESULTS_FILE, "w", newline="") as csvfile:
12+
writer = csv.writer(csvfile)
13+
writer.writerow(["Directory", "Time (s)", "Peak RAM (MB)"])
14+
15+
16+
def run_and_trace(cmd):
17+
start_time = time.time()
18+
process = subprocess.Popen(cmd, shell=True)
19+
proc = psutil.Process(process.pid)
20+
peak_mem = 0
21+
22+
while process.poll() is None:
23+
try:
24+
mem = proc.memory_info().rss / (1024 * 1024) # MB
25+
if mem > peak_mem:
26+
peak_mem = mem
27+
except psutil.NoSuchProcess:
28+
break
29+
time.sleep(0.1)
30+
31+
end_time = time.time()
32+
return end_time - start_time, peak_mem
33+
34+
35+
for dir_name in DIRS:
36+
cmd = f"virtualship run ../{dir_name} --from-data ../data"
37+
print(f"Running: {cmd}")
38+
elapsed, peak_mem = run_and_trace(cmd)
39+
# Write result after each iteration
40+
with open(RESULTS_FILE, "a", newline="") as csvfile:
41+
writer = csv.writer(csvfile)
42+
writer.writerow([dir_name, f"{elapsed:.2f}", f"{peak_mem:.2f}"])
43+
44+
print(f"\nResults written to {RESULTS_FILE}")
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import numpy as np
2+
import pandas as pd
3+
from matplotlib import pyplot as plt
4+
5+
# data
6+
df_default = pd.read_csv("results/performance_results.csv")
7+
df_fromdata = pd.read_csv("results/performance_results_fromdata.csv")
8+
9+
## plot
10+
fig, ax = plt.subplots(1, 1, figsize=(12, 7), dpi=96)
11+
12+
MARKERSIZE = 75
13+
LINEWIDTH = 2.5
14+
ymin, ymax, interval = 0, 800, 100
15+
16+
FROM_DATA = True
17+
LAST_POINT = True
18+
19+
SHOW_UNDERWAY_FROMDATA = False
20+
21+
xticks = [
22+
"Just CTD",
23+
"CTD + CTD_BGC",
24+
"CTD + CTD_BGC \n+ Drifters",
25+
"CTD + CTD_BGC \n+ Drifters + Argo Floats",
26+
"CTD + CTD_BGC \n+ Drifters + Argo Floats \n+ ADCP/Underway S/T",
27+
]
28+
29+
# default
30+
ax.scatter(
31+
df_default["Directory"],
32+
df_default["Time (s)"],
33+
label="on-the-fly (via copernicusmarine)",
34+
color="dodgerblue",
35+
s=MARKERSIZE,
36+
zorder=3,
37+
)
38+
ax.plot(
39+
df_default["Directory"],
40+
df_default["Time (s)"],
41+
lw=LINEWIDTH,
42+
ls="dotted",
43+
color="dodgerblue",
44+
zorder=3,
45+
)
46+
47+
# fromdata
48+
if FROM_DATA:
49+
ax.scatter(
50+
df_fromdata["Directory"] if LAST_POINT else df_fromdata["Directory"][:-1],
51+
df_fromdata["Time (s)"] if LAST_POINT else df_fromdata["Time (s)"][:-1],
52+
label="from-data (pre-downloaded data)",
53+
color="crimson",
54+
s=MARKERSIZE,
55+
zorder=3,
56+
)
57+
ax.plot(
58+
df_fromdata["Directory"] if LAST_POINT else df_fromdata["Directory"][:-1],
59+
df_fromdata["Time (s)"] if LAST_POINT else df_fromdata["Time (s)"][:-1],
60+
lw=LINEWIDTH,
61+
ls="dotted",
62+
color="crimson",
63+
zorder=3,
64+
)
65+
66+
# x/y ticks/lims
67+
if not SHOW_UNDERWAY_FROMDATA:
68+
ax.set_ylim(ymin, ymax + interval)
69+
yticks = np.arange(ymin, ymax + 1, interval)
70+
elif SHOW_UNDERWAY_FROMDATA:
71+
ax.set_ylim(ymin, ymax * 5 + interval)
72+
yticks = np.arange(ymin, ymax * 5 + 1, 5 * interval)
73+
ax.set_yticks(yticks)
74+
ax.set_yticklabels([round(val, 0) for val in yticks / 60.0]) # [minutes]
75+
ax.set_xticks(range(len(xticks)))
76+
ax.set_xticklabels(xticks, rotation=45, ha="right")
77+
78+
# axes labels
79+
ax.set_ylabel("Time (minutes)")
80+
81+
# grid
82+
ax.set_facecolor("gainsboro")
83+
ax.grid(True, alpha=1.0, color="white")
84+
85+
# title
86+
# ax.set_title("MHW expedition performance [64GB RAM, 8 cores]")
87+
88+
plt.legend(loc="upper left")
89+
90+
plt.tight_layout()
91+
plt.show()
92+
93+
94+
# TODO: add machine spec info to plot (annotate or whatever)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Directory,Time (s),Peak RAM (MB)
2+
CTD,39.49,0.95
3+
plus_CTD_BGC,132.87,0.93
4+
plus_DRIFTER,155.63,0.95
5+
plus_ARGO,506.98,0.96
6+
plus_UNDERWAY,796.10,0.97
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Directory,Time (s),Peak RAM (MB)
2+
CTD,13.73,0.98
3+
plus_CTD_BGC,24.85,0.99
4+
plus_DRIFTER,32.48,0.95
5+
plus_ARGO,96.63,0.95
6+
plus_UNDERWAY,3969.64,0.99

0 commit comments

Comments
 (0)