-
Notifications
You must be signed in to change notification settings - Fork 1
/
amdgpu-sensors-monitor.py
61 lines (51 loc) · 2.06 KB
/
amdgpu-sensors-monitor.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
#!/usr/bin/python3
# uses a running amdgpu-sensors-daemon.py to display a simple gpu monitor in the terminal
import os
import sys
import time
if __name__ == "__main__":
# folder to find sensor files
root = "/tmp/amdgpu-sensors"
# refresh interval
sleep_secs = 1
# values to get
gpu_temperature = 0
gpu_usage = 0
gpu_frequency = 0
gpu_power = 0
gpu_voltage = 0
mem_frequency = 0
mem_usage = 0
try:
while (True):
# reads data from the sensor files
mem_frequency = open(os.path.join(root, "mem_frequency"), "r").read()
gpu_frequency = open(os.path.join(root, "gpu_frequency"), "r").read()
gpu_voltage = open(os.path.join(root, "gpu_voltage"), "r").read()
gpu_power = open(os.path.join(root, "gpu_power"), "r").read()
gpu_temperature = open(os.path.join(root, "gpu_temperature"), "r").read()
gpu_usage = open(os.path.join(root, "gpu_usage"), "r").read()
mem_usage = open(os.path.join(root, "mem_usage"), "r").read()
# shows all info on the terminal
print("mem_frequency:", mem_frequency, "MHz")
print("gpu_frequency:", gpu_frequency, "MHz")
print("gpu_voltage:", gpu_voltage, "mV")
print("gpu_power:", gpu_power, "W")
print("gpu_temperature:", gpu_temperature, "C")
print("gpu_usage:", gpu_usage, "%")
print("mem_usage:", mem_usage, "MB")
# sleep
time.sleep(sleep_secs)
# erases 7 lines upwards
for i in range(0, 7):
sys.stdout.write('\x1b[1A')
sys.stdout.write('\x1b[2K')
# smooth exiting with CTRL+C
except(KeyboardInterrupt):
exit("")
# message displayed when a file is not found, possibly the daemon isn't running
except(FileNotFoundError):
exit("File not found: are you sure amdgpu-sensors-daemon.py is running?")
# all other cases
except():
exit()