perf: 量化商品页打开耗时并去重检查 (#109)

This commit is contained in:
chengma
2026-08-10 17:40:44 +08:00
parent 4c9bf3865b
commit ba0706dc47
13 changed files with 693 additions and 72 deletions
+16 -2
View File
@@ -10,6 +10,8 @@ import threading
from contextlib import AbstractContextManager
from typing import Any, Callable, Optional
from .performance_timing import current_performance_trace
PDD_PACKAGE_NAME = "com.xunmeng.pinduoduo"
@@ -30,10 +32,12 @@ class PddDeviceSession(AbstractContextManager[Any]):
self,
device: Any,
serial: str,
initial_app_state: dict[str, Any],
release: Callable[[], None],
) -> None:
self._device = device
self.serial = serial
self.initial_app_state = dict(initial_app_state)
self._release = release
self._owner_thread_id = threading.get_ident()
self._closed = False
@@ -107,8 +111,17 @@ class PddDeviceService:
self._active_serial = checked_serial
try:
device = self._connector(checked_serial)
current = device.app_current()
trace = current_performance_trace()
if trace is None:
device = self._connector(checked_serial)
else:
with trace.stage("uiautomator2_connect"):
device = self._connector(checked_serial)
if trace is None:
current = device.app_current()
else:
with trace.stage("first_app_current"):
current = device.app_current()
if not isinstance(current, dict):
raise RuntimeError("uiautomator2 未返回有效的设备状态")
except PddDeviceError:
@@ -130,6 +143,7 @@ class PddDeviceService:
return PddDeviceSession(
device,
checked_serial,
current,
lambda: self._release(checked_serial),
)