-
Notifications
You must be signed in to change notification settings - Fork 42
/
gpuGraph.py
executable file
·91 lines (70 loc) · 2.41 KB
/
gpuGraph.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python
# MIT License
# Copyright (c) 2018 Jetsonhacks
import sys
import subprocess
import getpass
import os
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from collections import deque
remote = ''
pwd = ''
if len(sys.argv) > 1:
remote = sys.argv[1]
pwd = getpass.getpass(prompt=remote.split("@")[0]+' password: ', stream=None)
gpuLoadFile="/sys/devices/gpu.0/load"
# On the Jetson TX1 this is a symbolic link to:
# gpuLoadFile="/sys/devices/platform/host1x/57000000.gpu/load"
# On the Jetson TX2, this is a symbolic link to:
# gpuLoadFile="/sys/devices/platform/host1x/17000000.gp10b/load"
fig = plt.figure(figsize=(6,2))
plt.subplots_adjust(top=0.85, bottom=0.30)
fig.set_facecolor('#F2F1F0')
fig.canvas.set_window_title('GPU Activity Monitor')
# Subplot for the GPU activity
gpuAx = plt.subplot2grid((1,1), (0,0), rowspan=2, colspan=1)
# For the comparison
gpuLine, = gpuAx.plot([],[])
# The line points in x,y list form
gpuy_list = deque([0]*240)
gpux_list = deque(np.linspace(60,0,num=240))
fill_lines=0
def initGraph():
global gpuAx
global gpuLine
global fill_lines
gpuAx.set_xlim(60, 0)
gpuAx.set_ylim(-5, 105)
gpuAx.set_title('GPU History')
gpuAx.set_ylabel('GPU Usage (%)')
gpuAx.set_xlabel('Seconds');
gpuAx.grid(color='gray', linestyle='dotted', linewidth=1)
gpuLine.set_data([],[])
fill_lines=gpuAx.fill_between(gpuLine.get_xdata(),50,0)
return [gpuLine] + [fill_lines]
def updateGraph(frame):
global fill_lines
global gpuy_list
global gpux_list
global gpuLine
global gpuAx
# Now draw the GPU usage
gpuy_list.popleft()
if len(remote) == 0:
with open(gpuLoadFile, 'r') as gpuFile:
fileData = gpuFile.read()
else:
cmd = "sshpass -p "+pwd+" ssh "+remote+" cat "+gpuLoadFile
fileData = subprocess.check_output(cmd.split(" ")).decode("utf-8")
# The GPU load is stored as a percentage * 10, e.g 256 = 25.6%
gpuy_list.append(int(fileData)/10)
gpuLine.set_data(gpux_list,gpuy_list)
fill_lines.remove()
fill_lines=gpuAx.fill_between(gpux_list,0,gpuy_list, facecolor='cyan', alpha=0.50)
return [gpuLine] + [fill_lines]
# Keep a reference to the FuncAnimation, so it does not get garbage collected
animation = FuncAnimation(fig, updateGraph, frames=200,
init_func=initGraph, interval=250, blit=True)
plt.show()