-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
68 lines (55 loc) · 2.66 KB
/
plot.py
File metadata and controls
68 lines (55 loc) · 2.66 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
import argparse
import os
import pandas as pd
import numpy as np
import socket
import matplotlib.pyplot as plt
from pathlib import Path
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--path', type=str, default='./results', help="Specify the path to load the results")
parser.add_argument('-t','--timestamp', type=str, default=None, help="Specify the timestamp when the experiement started")
args = parser.parse_args()
if args.timestamp is None:
log = args.path+'/'+np.sort(os.listdir(args.path))[-1]
else:
log = args.path+'/'+args.timestamp
log_path = Path(log)
csv_files = sorted([p for p in log_path.glob("*.csv")])
# Separate USAGE.csv (per‑user) from per‑device CSVs (CPU.csv, GPU_*.csv)
usage_file = next((p for p in csv_files if p.name.upper() == "USAGE.CSV"), None)
device_files = [p for p in csv_files if p is not usage_file]
# ---- Plot per‑device utilisation/memory (original behaviour) ----
if device_files:
dfs = [pd.read_csv(fp) for fp in device_files]
devices = [fp.stem for fp in device_files]
fig1, ax1 = plt.subplots(2, figsize=(12, 10))
fig1.suptitle(f"{socket.gethostname()} – Device metrics")
for df, d in zip(dfs, devices):
df['Time'] = pd.to_datetime(df['Time'], format="%H:%M-%d-%m-%Y")
ax1[0].plot(df['Time'], df['Util'], label=d)
ax1[1].plot(df['Time'], df['Mem'], label=d)
ax1[0].legend(); ax1[0].set_ylabel("Utilisation %")
ax1[1].legend(); ax1[1].set_ylabel("Memory %")
fig1.tight_layout()
fig1.savefig(log_path / "device_plot.pdf")
print(f"Device plots saved to {log_path/'device_plot.pdf'}")
# ---- Plot per‑user CPU / GPU usage from USAGE.csv ----
if usage_file is not None and usage_file.exists():
df_u = pd.read_csv(usage_file)
df_u['Time'] = pd.to_datetime(df_u['Time'], format="%H:%M-%d-%m-%Y")
users = df_u['User'].unique()
fig2, ax2 = plt.subplots(3, figsize=(12, 12))
fig2.suptitle(f"{socket.gethostname()} – Per‑user metrics")
for u in users:
sub = df_u[df_u['User'] == u]
ax2[0].plot(sub['Time'], sub['CPU_Util'], label=u)
ax2[1].plot(sub['Time'], sub['CPU_Mem'], label=u)
ax2[2].plot(sub['Time'], sub['GPU_Mem_GB'], label=u)
ax2[0].set_ylabel("CPU Util %")
ax2[1].set_ylabel("CPU Mem %")
ax2[2].set_ylabel("GPU Mem (GB)")
for a in ax2: a.legend()
fig2.tight_layout()
fig2.savefig(log_path / "usage_plot.pdf")
print(f"Per‑user plots saved to {log_path/'usage_plot.pdf'}")