Files
douyin_guaji-main/tools/logs/analyze_optimization_effect.py
T
CodexandClaude Opus 4.5 a19fa35a0f chore: 整理 tools/ 47 个脚本按功能分组
- diagnostics/ 11 个:环境/配置/依赖诊断
- logs/ 7 个:日志分析与查看
- coords/ 6 个:坐标拾取与区域选择
- cleanup/ 3 个:代码清理工具
- adb/ 2 个:ADB / 输入法相关
- windows/ 4 个:Windows 系统修复(备份)
- dev/ 9 个:开发辅助 / 运行时探测

并更新 tools/README.md 描述新结构。
删除 3 个明显的临时调试脚本 (_dump_lines.py / tmp_*.py)。

tools/ 不被业务代码 import,分组仅为人工浏览方便。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-05-20 23:25:28 +08:00

140 lines
5.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""分析优化效果"""
import sys
import os
import re
from datetime import datetime
if sys.platform == 'win32':
try:
# 尝试使用reconfigure方法(Python 3.7+)
reconfigure_func = getattr(sys.stdout, 'reconfigure', None)
if reconfigure_func:
reconfigure_func(encoding='utf-8')
except Exception:
try:
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
except Exception:
pass
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def main():
log_file = "logs/unified_2025-12-31.log"
if not os.path.exists(log_file):
print("日志文件不存在")
return
with open(log_file, 'r', encoding='utf-8', errors='replace') as f:
lines = f.readlines()
print("=" * 60)
print("优化效果分析")
print("=" * 60)
print()
# 1. 检查服务启动
service_started = False
for line in lines:
if '截图服务' in line and '已启动' in line:
service_started = True
print("✅ 服务已启动")
# 提取时间
time_match = re.search(r'(\d{2}:\d{2}:\d{2})', line)
if time_match:
print(f" 启动时间: {time_match.group(1)}")
break
if not service_started:
print("❌ 服务未启动")
return
# 2. 分析服务启动后的截图性能
service_start_time = None
screenshot_times_after_service = []
for i, line in enumerate(lines):
if '截图服务' in line and '已启动' in line:
time_match = re.search(r'(\d{2}:\d{2}:\d{2})', line)
if time_match:
h, m, s = map(int, time_match.group(1).split(':'))
service_start_time = h * 3600 + m * 60 + s
print(f" 服务启动时间戳: {service_start_time}")
break
if service_start_time:
# 分析服务启动后的截图耗时
for line in lines:
if 'screenshot_elapsed_seconds' in line:
time_match = re.search(r'(\d{2}:\d{2}:\d{2})', line)
if time_match:
h, m, s = map(int, time_match.group(1).split(':'))
log_time = h * 3600 + m * 60 + s
if log_time >= service_start_time:
elapsed_match = re.search(r'screenshot_elapsed_seconds=([\d.]+)', line)
if elapsed_match:
elapsed = float(elapsed_match.group(1))
screenshot_times_after_service.append(elapsed)
if screenshot_times_after_service:
print()
print("服务启动后的截图性能:")
print(f" 次数: {len(screenshot_times_after_service)}")
print(f" 平均耗时: {sum(screenshot_times_after_service) / len(screenshot_times_after_service):.2f}秒")
print(f" 最短耗时: {min(screenshot_times_after_service):.2f}秒")
print(f" 最长耗时: {max(screenshot_times_after_service):.2f}秒")
# 分析快速响应(可能是缓存命中)
fast_responses = [t for t in screenshot_times_after_service if t < 0.5]
if fast_responses:
print(f"\n ✅ 发现 {len(fast_responses)} 次快速响应(< 0.5秒)")
print(f" 说明缓存可能生效")
else:
print(f"\n ⚠️ 未发现快速响应(< 0.5秒)")
print(f" 可能原因:缓存未命中或服务未正常工作")
# 3. 检查代码集成
print()
print("=" * 60)
print("代码集成检查")
print("=" * 60)
# 检查 Underlying_Operations.py
if os.path.exists("Underlying_Operations.py"):
with open("Underlying_Operations.py", 'r', encoding='utf-8') as f:
content = f.read()
if 'use_service' in content and 'ScreenshotService' in content:
print("✅ Underlying_Operations.py 已支持服务模式")
else:
print("❌ Underlying_Operations.py 未支持服务模式")
print()
print("=" * 60)
print("结论")
print("=" * 60)
if service_started:
if screenshot_times_after_service:
avg = sum(screenshot_times_after_service) / len(screenshot_times_after_service)
if avg < 1.0:
print("✅ 优化生效!平均耗时 < 1秒")
elif avg < 2.0:
print("⚠️ 优化部分生效,平均耗时 1-2秒")
print(" 可能原因:缓存未完全生效")
else:
print("❌ 优化未生效,平均耗时 >= 2秒")
print(" 可能原因:")
print(" 1. 缓存未命中")
print(" 2. 服务未正常工作")
print(" 3. 某些调用未使用服务模式")
else:
print("⚠️ 服务已启动,但未找到截图耗时数据")
else:
print("❌ 服务未启动,需要重新运行程序")
if __name__ == '__main__':
main()