test(benchmark): add StartupBenchmark for cold launch timing
This commit is contained in:
parent
ccffcfb052
commit
66be0be3c4
@ -1,16 +1,19 @@
|
||||
<!-- Parent: ../../../../../../../AGENTS.md -->
|
||||
<!-- Generated: 2026-05-22 | Updated: 2026-05-22 -->
|
||||
<!-- Generated: 2026-05-22 | Updated: 2026-06-15 -->
|
||||
|
||||
# baseline
|
||||
|
||||
## Purpose
|
||||
Baseline Profile 自动生成器。通过 UI Automator 模拟完整用户交互路径(冷启动、FAB 展开、年/月视图切换、日期选择、折叠/展开、关于页、开源许可页),生成 AOT 编译优化所需的 startup profile。
|
||||
Baseline Profile 自动生成器与启动性能基准测试。包含:
|
||||
- `BaselineProfileGenerator.kt`:通过 UI Automator 模拟完整用户交互路径(冷启动、FAB 展开、年/月视图切换、日期选择、折叠/展开、关于页、开源许可页),生成 AOT 编译优化所需的 startup profile。
|
||||
- `StartupBenchmark.kt`:冷启动性能基准测试,测量 `timeToInitialDisplay` 与 `timeToFullDisplay`。
|
||||
|
||||
## Key Files
|
||||
|
||||
| File | Description |
|
||||
|------|-------------|
|
||||
| `BaselineProfileGenerator.kt` | Profile 生成测试类,覆盖全部用户交互路径 |
|
||||
| `StartupBenchmark.kt` | 冷启动基准测试类,覆盖 Full/Partial/None 三种编译模式 |
|
||||
|
||||
## Subdirectories
|
||||
无
|
||||
@ -23,13 +26,15 @@ Baseline Profile 自动生成器。通过 UI Automator 模拟完整用户交互
|
||||
- 每个操作后调用 `device.waitForIdle()` 等待动画完成
|
||||
|
||||
### Testing Requirements
|
||||
- 运行:`./gradlew :macrobenchmark:updateBaselineProfile`
|
||||
- 生成 Profile:`./gradlew :macrobenchmark:updateBaselineProfile`
|
||||
- 运行冷启动基准(仅该类):`./gradlew :macrobenchmark:connectedBenchmarkAndroidTest --tests "plus.rua.project.baseline.StartupBenchmark"`
|
||||
- 需要设备/模拟器连接,应用已安装在 benchmark 构建类型下
|
||||
|
||||
## Dependencies
|
||||
|
||||
### External
|
||||
- `androidx.benchmark.macro.junit4.BaselineProfileRule`
|
||||
- `androidx.benchmark.macro.junit4.MacrobenchmarkRule`
|
||||
- `androidx.test.uiautomator`
|
||||
|
||||
<!-- MANUAL: -->
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
package plus.rua.project.baseline
|
||||
|
||||
import androidx.benchmark.macro.CompilationMode
|
||||
import androidx.benchmark.macro.StartupMode
|
||||
import androidx.benchmark.macro.StartupTimingMetric
|
||||
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
/**
|
||||
* 冷启动性能基准测试。
|
||||
*
|
||||
* 测量指标:
|
||||
* - timeToInitialDisplay:从 intent 到首帧显示
|
||||
* - timeToFullDisplay:从 intent 到 reportFullyDrawn()/ReportDrawn() 被触发
|
||||
*
|
||||
* 运行方式:
|
||||
* ```
|
||||
* ./gradlew :macrobenchmark:connectedBenchmarkAndroidTest --tests "plus.rua.project.baseline.StartupBenchmark"
|
||||
* ```
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class StartupBenchmark {
|
||||
|
||||
@get:Rule
|
||||
val benchmarkRule = MacrobenchmarkRule()
|
||||
|
||||
@Test
|
||||
fun startupColdFull() = startup(CompilationMode.Full())
|
||||
|
||||
@Test
|
||||
fun startupColdPartial() = startup(CompilationMode.Partial())
|
||||
|
||||
@Test
|
||||
fun startupColdNone() = startup(CompilationMode.None())
|
||||
|
||||
private fun startup(compilationMode: CompilationMode) {
|
||||
benchmarkRule.measureRepeated(
|
||||
packageName = "plus.rua.project",
|
||||
metrics = listOf(StartupTimingMetric()),
|
||||
compilationMode = compilationMode,
|
||||
startupMode = StartupMode.COLD,
|
||||
iterations = 5,
|
||||
setupBlock = {
|
||||
pressHome()
|
||||
},
|
||||
measureBlock = {
|
||||
startActivityAndWait()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user