-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory-plot
executable file
·38 lines (27 loc) · 919 Bytes
/
memory-plot
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
#!/home/fred/micromamba/envs/default/bin/python
"""
Take a file produced with memory-log, plot it and write to disk.
Usage:
$ memory-plot <log_file>
"""
import logging
import os
import sys
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
if __name__ == "__main__":
logging.basicConfig(format="%(asctime)s %(process)d %(filename)s %(message)s", level=logging.INFO)
matplotlib.use('Agg')
_, log_path = sys.argv
df = pd.read_csv(log_path)
df["datetime"] = pd.to_datetime(df.datetime)
logging.info(f"\n{df.head()}")
f, ax = plt.subplots()
df.plot(x="datetime", y="used", ax=ax)
df.plot(x="datetime", y="total", ax=ax)
plot_path = os.path.splitext(log_path)[0] + ".png"
if os.path.exists(plot_path):
raise RuntimeError(f"{plot_path} already exists, please delete.")
f.savefig(plot_path)
logging.info(f"Written plot to {plot_path}")