import os
results = os.popen("nvidia-smi").read().split("\n")
outputs = []
index = results.index("| Processes: GPU Memory |")
for i in range(index+3, len(results)-2):
process = results[i].strip().split()
pid = process[2].strip()
user = os.popen("lsof -p " + pid).read().strip().split("\n")[-1].split()[2]
process.append(user)
outputs.append(process)
print("\n".join(results[0:index+1]))
print("| GPU PID Type Process name User name Usage |")
print(results[index+2])
space_num=[4, 8, 9, 4, 20, 21, 11]
for p in outputs:
print("|"+" "*space_num[0]+p[1]+" "*(space_num[1]-len(p[1]))+p[2]+" "*(space_num[2]-len(p[2]))+p[3] \
+" "*(space_num[3]-len(p[3]))+p[4]+" "*(space_num[4]-len(p[4]))+p[-1]+" "*(space_num[5]-len(p[-1]))+p[5]+" "*(space_num[6]-len(p[5]))+"|")
print(results[-2])
Nvidia-smi.py
最新推荐文章于 2024-04-18 10:20:55 发布