* Add automated baseline profile generation * Create benchmark build type And remove the `enabledRules` argument as it will be injected by baseline profile gradle plugin.
45 lines
1.4 KiB
Kotlin
45 lines
1.4 KiB
Kotlin
package com.ehviewer.baselineprofile
|
|
|
|
import androidx.benchmark.macro.BaselineProfileMode
|
|
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 androidx.test.platform.app.InstrumentationRegistry
|
|
import org.junit.Rule
|
|
import org.junit.Test
|
|
import org.junit.runner.RunWith
|
|
|
|
@RunWith(AndroidJUnit4::class)
|
|
class StartupBenchmarks {
|
|
|
|
@get:Rule
|
|
val rule = MacrobenchmarkRule()
|
|
|
|
@Test
|
|
fun startupCompilationNone() =
|
|
benchmark(CompilationMode.None())
|
|
|
|
@Test
|
|
fun startupCompilationBaselineProfiles() =
|
|
benchmark(CompilationMode.Partial(BaselineProfileMode.Require))
|
|
|
|
private fun benchmark(compilationMode: CompilationMode) {
|
|
rule.measureRepeated(
|
|
packageName = InstrumentationRegistry.getArguments().getString("targetAppId")
|
|
?: throw Exception("targetAppId not passed as instrumentation runner arg"),
|
|
metrics = listOf(StartupTimingMetric()),
|
|
compilationMode = compilationMode,
|
|
startupMode = StartupMode.COLD,
|
|
iterations = 10,
|
|
setupBlock = {
|
|
pressHome()
|
|
},
|
|
measureBlock = {
|
|
startActivityAndWait()
|
|
},
|
|
)
|
|
}
|
|
}
|