Skip to content

Instantly share code, notes, and snippets.

@mxbi
Created January 24, 2018 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mxbi/51b5ec3fa16c447accbf14343bb4e52e to your computer and use it in GitHub Desktop.
Save mxbi/51b5ec3fa16c447accbf14343bb4e52e to your computer and use it in GitHub Desktop.
Logging GPU and CPU temperature
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