-
Notifications
You must be signed in to change notification settings - Fork 0
/
sysInfo.py
55 lines (39 loc) · 1.3 KB
/
sysInfo.py
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
import psutil
import matplotlib.pyplot as plt
from collections import deque
import numpy as np
import matplotlib.animation as animation
from matplotlib.ticker import FuncFormatter
from gpuinfo import GPUInfo
def init():
line1.set_ydata([np.nan] * len(x))
line2.set_ydata([np.nan] * len(x))
return line1,line2,
def animate(i):
# Add next value
# data.append(np.random.randint(0, max_val))
val = psutil.cpu_percent()
val2 = psutil.virtual_memory()[2]
data.append(val)
data2.append(val2)
line1.set_ydata(data)
line2.set_ydata(data2)
return line1,line2,
max_x = 60
max_val = 100
arr = [0 for i in range(max_x)]
data = deque(np.zeros(max_x), maxlen=max_x) # hold the last 10 values
data2 = deque(np.zeros(max_x), maxlen=max_x)
x = np.arange(0, max_x)
fig, ax = plt.subplots()
ax.set_ylim(0, max_val)
ax.set_xlim(0, max_x-1)
line1, = ax.plot(x, np.random.randint(0, max_val, max_x))
line2, = ax.plot(x, np.random.randint(0, max_val, max_x))
ax.xaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{:.0f}s'.format(max_x - x - 1)))
plt.xlabel('Seconds ago')
plt.ylabel('Usage %')
plt.legend(['CPU Usage %', 'Memory Usage %'], loc='upper left')
ani = animation.FuncAnimation(
fig, animate, init_func=init, interval=1000, blit=True, save_count=10)
plt.show()