Files
douyin_guaji-main/SCREENSHOT_VERIFICATION_GUIDE.md
T
Your Name a0aad21835 feat: Optimize ADB exec-out and OCR performance
- Introduced performance enhancements for ADB exec-out, reducing execution time by 10-20% through the use of Popen with streaming reads, increased buffer sizes, and removal of unnecessary fsync calls.
- Implemented optimizations in OCR processing, cutting recognition time by 50% by refining button recognition logic and improving image loading and preprocessing methods.
- Added detailed performance diagnostics and configuration options to facilitate further optimizations.
- Created new documentation files outlining the performance improvements and recommendations for future enhancements.
2026-01-02 02:06:01 +08:00

4.2 KiB
Raw Blame History

强制直接截图验证指南

修改摘要

已强制所有截图调用使用直接截图模式(use_service=False),避免后台服务等待导致的 ~5-6s 阻塞。

修改的文件

  1. operations/screenshot_operations.py

    • get_screenshot() 默认参数已为 use_service=False
    • 全局函数 get_screenshot() 也显式支持 use_service 参数
  2. Underlying_Operations.py

    • get_screenshot() 默认参数从 True 改为 False
  3. 所有调用点已更新(显式传递 use_service=False):

    • douyin/core/douyin_fudai.py - 阶段诊断截图
    • douyin/detection/douyin_detection.py - 检测相关截图
    • douyin/fudai/douyin_fudai_finder.py - 福袋查找截图
    • douyin/fudai/core/fudai_attend.py - 参与相关截图
    • douyin/fudai/douyin_fudai_core.py - 核心流程截图
    • douyin/core/douyin_flow_control.py - 流程控制截图
    • douyin/reservation/ - 预约相关截图
    • douyin/stage/douyin_stage_handler.py - 阶段处理截图
    • douyin/handlers/ - 各种处理器截图
    • gui/ - GUI 相关截图

验证步骤

1. 重启程序

确保所有修改已生效:

# 停止当前运行的程序(如果正在运行)
# 然后重新启动
python your_main_script.py

2. 实时监控日志

在 PowerShell 中运行以下命令实时查看截图相关日志:

Get-Content .\logs\unified_*.log -Tail 200 -Wait | Select-String -Pattern "screenshot_elapsed_seconds|exec-out duration|截图服务|TIMEOUT|获取屏幕截图成功"

3. 期望的日志输出

应该看到的(正常):

  • [截图] [OK] 获取屏幕截图成功 (exec-out,耗时: XXXms) - exec-out 成功
  • [截图] [OK] 获取屏幕截图成功 (回退方案,耗时: XXXms) - shell+pull 回退
  • [DEBUG] exec-out duration: XXXms - exec-out 耗时
  • screenshot_elapsed_seconds=0.6 到 1.8 左右(正常范围)

不应该看到的(问题):

  • [截图服务] [TIMEOUT] 等待超时 - 不应该再出现
  • [截图服务] 后台截图失败 - 不应该再出现
  • screenshot_elapsed_seconds=5.0 或更高 - 不应该再出现

4. 验证关键路径

运行一次阶段检测,观察日志:

  1. 查找包含 截图+阶段诊断 的日志行
  2. 检查 screenshot_elapsed_seconds 的值
  3. 应该从之前的 ~5s 降低到 ~0.6-1.8s

示例日志(期望):

[2026-01-02 00:39:30.431] [INFO] [截图] [douyin_fudai.py:<lambda>:72] 截图+阶段诊断 阶段=IN_LIVE_ROOM 识别=... 字段_elapsed_seconds=1.2 字段_screenshot_elapsed_seconds=0.8

5. 性能对比

修改前:

  • screenshot_elapsed_seconds: ~4.8-5.3 秒
  • 大量 [TIMEOUT] 等待超时 日志

修改后(期望):

  • screenshot_elapsed_seconds: ~0.6-1.8 秒
  • 无超时日志
  • 直接使用 exec-out 或回退到 shell+pull

故障排查

如果截图仍然很慢(>2秒)

  1. 检查 ADB 连接:

    adb devices
    

    确保设备已连接且状态为 device

  2. 检查 exec-out 是否成功: 查看日志中是否有 exec-out 异常 或 回退方案 的提示

    • 如果频繁回退,可能是设备不支持 exec-out 或连接不稳定
  3. 检查是否有重试: 查看日志中是否有 截图失败,重试中 的提示

    • 如果频繁重试,可能是设备响应慢或连接问题

如果出现错误

  1. 检查日志中的错误信息
  2. 确认设备连接正常
  3. 检查 ADB 版本兼容性

回滚方法

如果需要恢复流式截图服务:

  1. 修改 Underlying_Operations.py 中 get_screenshot 的默认参数:

    def get_screenshot(self, device_id, path="pic", use_service: bool = True):
    
  2. 修改 operations/screenshot_operations.py 中 get_screenshot 的默认参数:

    def get_screenshot(self, device_id, path="pic", use_service: bool = True) -> bool:
    
  3. 重启程序

注意事项

  • 直接截图模式更稳定,但平均响应时间会比流式截图稍慢(~1.0-1.8s vs ~0.4s)
  • 但消除了 6s 的等待超时,总体性能提升明显
  • 所有截图调用现在都强制使用直接模式,确保一致性