#!/usr/bin/env python3 """截图服务诊断工具""" import time from operations.screenshot_service import ScreenshotService def diagnose_screenshot_service(): """诊断截图服务状态""" print("=== 截图服务诊断工具 ===\n") service = ScreenshotService.get_instance() cache_info = service.get_cache_info() print(f"1. 服务运行状态: {'[OK] 运行中' if cache_info['running'] else '[ERROR] 未运行'}") print(f"2. 设备ID: {cache_info.get('device_id', 'None')}") print(f"3. 截图间隔: {cache_info.get('interval', 'N/A')}秒") print(f"4. 缓存有效期: {cache_info.get('cache_valid_duration', 'N/A')}秒") last_time = cache_info.get('last_screenshot_time', 0) if last_time > 0: time_since = time.time() - last_time print(".1f") print(f"6. 缓存状态: {'[OK] 有效' if time_since < cache_info.get('cache_valid_duration', 2.0) else '[EXPIRED] 过期'}") else: print("5. 最后截图时间: 从未截图") print("6. 缓存状态: 无缓存") print(f"7. 最后截图成功: {cache_info.get('last_success', False)}") # 诊断建议 print("\n=== 诊断结果 ===") issues = [] if not cache_info['running']: issues.append("[ERROR] 后台截图服务未运行 - 每次截图都会很慢") if not cache_info.get('device_id'): issues.append("[ERROR] 设备ID为空 - 无法启动截图服务") if last_time == 0: issues.append("[ERROR] 从未成功截图 - 检查ADB连接和设备状态") if issues: print("发现问题:") for issue in issues: print(f" {issue}") else: print("[OK] 截图服务运行正常") # 显示性能预期 print("\n=== 性能预期 ===") print("- 缓存命中时: < 10ms") print("- 缓存未命中时: < 1秒") print("- 后台截图间隔: 1.5秒") print("\n=== 解决建议 ===") if not cache_info['running']: print("1. 重启程序,确保设备ID正确设置") print("2. 检查ADB连接: adb devices") print("3. 查看程序日志中的截图服务相关信息") if cache_info['running'] and last_time == 0: print("1. 检查ADB连接是否正常") print("2. 尝试手动截图测试连接") print("3. 检查设备是否进入睡眠模式") print("\n=== 测试命令 ===") print("运行测试: python test_full_screenshot_flow.py") if __name__ == "__main__": diagnose_screenshot_service()