-
-
Save simonkamronn/3fee2f4c5521c0c7f5691ac7a7265539 to your computer and use it in GitHub Desktop.
json formatting of nvidia-settings
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
#!/usr/bin/env python | |
# gpu_stat.py [DELAY [COUNT]] | |
# dump some gpu stats as a line of json | |
# {"util":{"PCIe":"0", "memory":"11", "video":"0", "graphics":"13"}, "used_mem":"161"} | |
import json, socket, subprocess, sys, time | |
try: | |
delay = int(sys.argv[1]) | |
except: | |
delay = 1 | |
try: | |
count = int(sys.argv[2]) | |
except: | |
count = None | |
i = 0 | |
while True: | |
GPU = socket.gethostname() + ":0[gpu:0]" | |
cmd = ['nvidia-settings', '-t', '-q', GPU + '/GPUUtilization'] | |
gpu_util = subprocess.check_output(cmd).strip().split(",") | |
gpu_util = dict([f.strip().split("=") for f in gpu_util]) | |
cmd[-1] = GPU + '/UsedDedicatedGPUMemory' | |
gpu_used_mem = subprocess.check_output(cmd).strip() | |
print json.dumps({"used_mem": gpu_used_mem, "util": gpu_util, "time": int(time.time())}) | |
if count != None: | |
i += 1 | |
if i == count: | |
exit(0) | |
time.sleep(delay) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment