74 lines
2.4 KiB
Python
74 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""检查后台截图服务状态"""
|
|
|
|
import time
|
|
from operations.screenshot_service import ScreenshotService
|
|
|
|
def main():
|
|
print("=== 后台截图服务状态检查 ===\n")
|
|
|
|
service = ScreenshotService.get_instance()
|
|
info = service.get_cache_info()
|
|
|
|
print("服务状态:")
|
|
print(f" 运行中: {info['running']}")
|
|
print(f" 设备ID: {info.get('device_id', 'None')}")
|
|
print(f" 截图间隔: {info.get('interval', 'N/A')}秒")
|
|
print(f" 缓存有效期: {info.get('cache_valid_duration', 'N/A')}秒")
|
|
|
|
last_time = info.get('last_screenshot_time', 0)
|
|
if last_time > 0:
|
|
time_since = time.time() - last_time
|
|
print(f"\n最后截图时间: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(last_time))}")
|
|
print(f" 距离现在: {time_since:.1f}秒前")
|
|
print(f" 缓存状态: {'有效' if time_since < info.get('cache_valid_duration', 4.0) else '已过期'}")
|
|
print(f" 最后成功: {info.get('last_success', False)}")
|
|
else:
|
|
print("\n最后截图时间: 从未截图")
|
|
print(" 缓存状态: 无缓存")
|
|
|
|
print("\n=== 诊断结果 ===")
|
|
|
|
if not info['running']:
|
|
print("[ERROR] 后台截图服务未运行")
|
|
print(" 原因: 服务可能未启动或已停止")
|
|
elif not info.get('device_id'):
|
|
print("[ERROR] 设备ID为空")
|
|
print(" 原因: 服务启动时未设置设备ID")
|
|
elif last_time == 0:
|
|
print("[WARN] 服务运行中但从未成功截图")
|
|
print(" 可能原因:")
|
|
print(" 1. ADB连接问题")
|
|
print(" 2. 设备未连接")
|
|
print(" 3. 截图操作失败")
|
|
elif time.time() - last_time > 10:
|
|
print("[WARN] 服务运行中但最近未截图")
|
|
print(f" 距离上次截图已过: {time.time() - last_time:.1f}秒")
|
|
print(" 可能原因: 后台线程异常或截图失败")
|
|
else:
|
|
print("[OK] 后台截图服务运行正常")
|
|
print(f" 缓存有效,响应时间应该 < 10ms")
|
|
|
|
# 检查是否有后台线程在运行
|
|
if hasattr(service, '_thread') and service._thread:
|
|
print(f"\n后台线程状态:")
|
|
print(f" 线程存在: True")
|
|
print(f" 线程存活: {service._thread.is_alive() if service._thread else False}")
|
|
else:
|
|
print("\n后台线程状态: 未创建")
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|