Created
January 24, 2018 22:10
-
-
Save mxbi/51b5ec3fa16c447accbf14343bb4e52e to your computer and use it in GitHub Desktop.
Logging GPU and CPU temperature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import mlcrate as mlc | |
import time | |
def get_stats(): | |
nv = subprocess.run(['nvidia-smi'], stdout=subprocess.PIPE).stdout.decode('unicode_escape') | |
gpu_temps = [] | |
for line in nv.split('\n'): | |
if len(line) > 11 and line[10] == 'C': | |
gpu_temps.append(int(line[8:10])) | |
sensors = subprocess.run(['sensors'], stdout=subprocess.PIPE).stdout.decode('unicode_escape') | |
cpu_temps = [] | |
for line in sensors.split('\n'): | |
if len(line) > 20 and line[16] == '+': | |
cpu_temps.append(int(line[17:19])) | |
return gpu_temps + cpu_temps | |
columns = ['time', *['gpu{}'.format(i) for i in range(4)], 'physical', *['cpu{}'.format(i) for i in range(8)]] | |
f = mlc.LinewiseCSVWriter('templog.csv', header=columns, append=True) | |
while True: | |
t0 = time.time() | |
stats = get_stats() | |
print(stats) | |
f.write([time.time(), *stats]) | |
time.sleep(5 - (t0 - time.time())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment