Add automated baseline profile generation (#1349)
* Add automated baseline profile generation * Create benchmark build type And remove the `enabledRules` argument as it will be injected by baseline profile gradle plugin.
This commit is contained in:
1 parent
4dd6d68163
commit
cb2d99bdc1
13 files changed
+292
-12
No files matched your search
@@ -0,0 +1,51 @@
|
||||
package com.ehviewer.baselineprofile
|
||||
|
||||
import androidx.benchmark.macro.junit4.BaselineProfileRule
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.By
|
||||
import androidx.test.uiautomator.Direction
|
||||
import androidx.test.uiautomator.Until
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class BaselineProfileGenerator {
|
||||
|
||||
@get:Rule
|
||||
val rule = BaselineProfileRule()
|
||||
|
||||
@Test
|
||||
fun generate() {
|
||||
rule.collect(
|
||||
packageName = InstrumentationRegistry.getArguments().getString("targetAppId")
|
||||
?: throw Exception("targetAppId not passed as instrumentation runner arg"),
|
||||
includeInStartupProfile = true,
|
||||
) {
|
||||
pressHome()
|
||||
startActivityAndWait()
|
||||
|
||||
// Onboarding
|
||||
if (device.hasObject(By.text("Username"))) {
|
||||
device.findObject(By.scrollable(true))?.run {
|
||||
scrollUntil(Direction.DOWN, Until.hasObject(By.text("Guest mode")))
|
||||
}
|
||||
device.findObject(By.text("Guest mode")).click()
|
||||
}
|
||||
|
||||
// Gallery list
|
||||
device.wait(Until.hasObject(By.text("NON-H")), 10_000)
|
||||
device.findObject(By.scrollable(true))?.run {
|
||||
fling(Direction.DOWN)
|
||||
click()
|
||||
}
|
||||
|
||||
// Gallery detail
|
||||
device.wait(Until.hasObject(By.text("Similar")), 10_000)
|
||||
device.findObject(By.hasDescendant(By.text("Read")).scrollable(true))?.fling(Direction.DOWN)
|
||||
|
||||
device.waitForIdle()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
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()
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user