import psutil
import datetime
import time
while True:
# 这里写你的代码
time.sleep(1) # 休眠1秒
# 获取显卡使用率和显存使用情况
gpu_usage = psutil.cpu_percent(interval=1, percpu=False)
gpu_memory = psutil.virtual_memory().used / (1024 * 1024)
now = datetime.datetime.now()
print("GPU usage: {}%".format(gpu_usage))
print("GPU memory usage: {} MB".format(gpu_memory))
data = "GPU 使用率:" + str(gpu_usage) + "%" + "GPU 内存使用率:" + str(gpu_memory) + "当前时间:" + str(now) + "\n"
# 打开文件并写入数据
with open("file.txt", "a") as f:
f.write(data)
'''
# 读取文件并输出内容
with open("file.txt", "r") as f:
print(f.read())
'''
获取windows显卡使用率,并写入txt文档
猜你喜欢
转载自blog.csdn.net/qq_45194089/article/details/129883810
今日推荐
周排行