import time
def monitor_delay():
delays = []
start_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
while True:
# 获取当前时间和帧率数字(这里用随机数代替)
current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
frame_rate = random.randint(40, 60) # 帧率随机在40到60之间
# 计算延迟值(假设延迟与帧率成反比)
delay = int(1000 / frame_rate)
delays.append(delay)
# 打印当前时间和延迟值
print(f"{current_time} {delay}ms")
# 每隔一秒统计一次
time.sleep(1)
# 结束监测(通过点击按钮等方式触发)
if end_monitor:
break
# 计算平均延迟
average_delay = sum(delays) // len(delays)
# 导出文档
with open("delay_report.txt", "w") as file:
for i in range(len(delays)):
file.write(f"{start_time} {i}s: {delays[i]}ms\n")
file.write(f"平均延迟:{average_delay}ms")
# 点击按钮开始监测(这里使用一个简单的变量作为示例)
end_monitor = False
monitor_delay()