feat: update gpu status code

This commit is contained in:
wql 2024-08-22 16:10:27 +08:00
parent d4cea6f9ac
commit 72df1af06e
1 changed files with 20 additions and 1 deletions

View File

@ -1,6 +1,8 @@
import json
import pynvml
import time
import psutil
def main():
UNIT = 1024 * 1024 * 1024
@ -22,13 +24,30 @@ def main():
powerusage_W = pynvml.nvmlDeviceGetPowerUsage(handle) / 1000
))
all_processes_status = []
pidAllInfo = pynvml.nvmlDeviceGetComputeRunningProcesses(handle)
for pidInfo in pidAllInfo:
pidUser = psutil.Process(pidInfo.pid).username()
pidCreateTime = psutil.Process(pidInfo.pid).create_time()
pidName = psutil.Process(pidInfo.pid).name()
all_gpu_status.append(dict(
pid = pidInfo.pid,
create_time = pidCreateTime,
name = pidName,
user = pidUser,
used_mem_GB = pidInfo.usedGpuMemory/UNIT
))
logs = dict(
cur_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
all_gpu_status = all_gpu_status
all_gpu_status = all_gpu_status,
all_processes_status = all_processes_status
)
with open("./results/gpu_status_0821.json", "a", encoding="utf-8") as f:
f.write(json.dumps(logs) + "\n")
print(logs)
time.sleep(60)
pynvml.nvmlShutdown()