Skip to content

feat: 增加 Native Hook 应用 Trace 采集 - #166

Closed
qiqingzhixin wants to merge 8 commits into
mainfrom
codex/issue-152-trace-capture
Closed

feat: 增加 Native Hook 应用 Trace 采集#166
qiqingzhixin wants to merge 8 commits into
mainfrom
codex/issue-152-trace-capture

Conversation

@qiqingzhixin

@qiqingzhixin qiqingzhixin commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

变更

  • 将通用 Trace 编排与应用操作场景分离:采集流程只依赖场景名称、目标 Bundle、prepareexercise
  • 提供 ApplicationScenario interface,以及 CalculatorScenarioNoteScenario 两个 adapter;后续应用通过新增并注册 adapter 扩展。
  • 新增 --scenario {calculator,note} 参数,默认仍为 calculator,保持原有命令兼容。
  • calculator 场景在采集前校验 100 * 100 = 10000,采集期间动态发现按钮并持续随机点击。
  • note 场景启动 com.ohos.note/MainAbility,确认 pages/MyNoteHome,在采集前从搜索框边界计算并缓存左、中、右三个安全点,采集期间持续随机点击。
  • 场景启动和必要准备是硬条件;profiler 启动后的随机操作只用于制造负载,失败记录告警但不否定成功生成的 Trace。
  • 所有点击坐标均从本次真实布局动态计算,不硬编码屏幕坐标。
  • 不使用 hmdriver2、Hypium Python Driver,也不创建、构建或安装额外 HAP。
  • SQLite 和 Excel 仅用于串联、验证 Trace 与符号转换,不在本 PR 建设生产级数据管道。

使用

脚本只使用 Python 标准库,无需安装额外 Python 依赖:

py tools/native_hook_capture.py --scenario calculator --duration 30
py tools/native_hook_capture.py --scenario note --duration 30

省略 --scenario 时默认使用 calculator。多设备或工具不在 PATH 时:

py tools/native_hook_capture.py `
  --scenario note `
  --duration 60 `
  --target 7001005458323933328a521c3c503800 `
  --hdc D:/soft/hdc/toolchains/hdc.exe `
  --trace-streamer D:/soft/trace_streamer_binary/trace_streamer_windows.exe

成功产物位于 target/trace/YYYYMMDD-HHMMSS/,包含 native_heap.htracetrace.dbhiprofiler.loguitest.logtrace-streamer.log。核心产物是 htrace;数据库是当前串联验证产物。

验证

  • 目标设备:7001005458323933328a521c3c503800,API 26,uitest 7.0.0.1
  • calculator:前置结果 10000,动态发现 18 个按钮。
  • note:动态发现三个搜索框安全点,30 秒采集期间随机点击 14 次,未修改笔记数据。
  • 备忘录数据库的 143,913 条 native_hook 记录全部关联 process.name=com.ohos.note
  • 最新 10 秒主流程回归生成 38,917,475 B htrace。
  • py -m py_compile tools/native_hook_capture.py tools/test_native_hook_capture.py
  • py tools/test_native_hook_capture.py:27 passed。
  • git diff --check
场景 配置时长 数据库时间范围 htrace 大小 trace.db 大小 native_hook 行数 结果 随机点击
calculator 30 秒 29.83 秒 42,669,350 B 16,986,112 B 182,324 10000 26
calculator 60 秒 59.89 秒 50,121,912 B 28,323,840 B 362,378 10000 26
calculator 120 秒 119.83 秒 58,813,446 B 42,143,744 B 572,425 10000 81
note 30 秒 28.20 秒 45,050,281 B 29,716,480 B 143,913 首页搜索框 14

四次均完成 trace_streamer 转换。

符号转换由 #167 独立交付。

Closes #168

Refs #152

@qiqingzhixin qiqingzhixin changed the title feat: 增加 Native Hook 计算器 Trace 采集 feat: 增加 Native Hook 应用 Trace 采集 Jul 20, 2026
@qiqingzhixin

Copy link
Copy Markdown
Collaborator Author

Branch was pushed to the upstream repository by mistake. Replaced by fork-based PR #171.

@qiqingzhixin
qiqingzhixin deleted the codex/issue-152-trace-capture branch July 21, 2026 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Native Hook 应用 Trace 采集

1 participant