- 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.
4.2 KiB
4.2 KiB
强制直接截图验证指南
修改摘要
已强制所有截图调用使用直接截图模式(use_service=False),避免后台服务等待导致的 ~5-6s 阻塞。
修改的文件
-
operations/screenshot_operations.pyget_screenshot()默认参数已为use_service=False- 全局函数
get_screenshot()也显式支持use_service参数
-
Underlying_Operations.pyget_screenshot()默认参数从True改为False
-
所有调用点已更新(显式传递
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. 验证关键路径
运行一次阶段检测,观察日志:
- 查找包含
截图+阶段诊断的日志行 - 检查
screenshot_elapsed_seconds的值 - 应该从之前的 ~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秒)
-
检查 ADB 连接:
adb devices确保设备已连接且状态为
device -
检查 exec-out 是否成功: 查看日志中是否有
exec-out 异常或回退方案的提示- 如果频繁回退,可能是设备不支持 exec-out 或连接不稳定
-
检查是否有重试: 查看日志中是否有
截图失败,重试中的提示- 如果频繁重试,可能是设备响应慢或连接问题
如果出现错误
- 检查日志中的错误信息
- 确认设备连接正常
- 检查 ADB 版本兼容性
回滚方法
如果需要恢复流式截图服务:
-
修改
Underlying_Operations.py中get_screenshot的默认参数:def get_screenshot(self, device_id, path="pic", use_service: bool = True): -
修改
operations/screenshot_operations.py中get_screenshot的默认参数:def get_screenshot(self, device_id, path="pic", use_service: bool = True) -> bool: -
重启程序
注意事项
- 直接截图模式更稳定,但平均响应时间会比流式截图稍慢(~1.0-1.8s vs ~0.4s)
- 但消除了 6s 的等待超时,总体性能提升明显
- 所有截图调用现在都强制使用直接模式,确保一致性