in MacrobenchmarkSample/macrobenchmark/src/main/java/com/example/macrobenchmark/frames/NonExportedActivityBenchmark.kt [46:87]
fun nonExportedActivityScrollList() {
benchmarkRule.measureRepeated(
// [START_EXCLUDE]
packageName = TARGET_PACKAGE,
metrics = listOf(FrameTimingMetric()),
// Try switching to different compilation modes to see the effect
// it has on frame timing metrics.
compilationMode = CompilationMode.None(),
startupMode = StartupMode.WARM, // Ensures that a new activity is created every single time
iterations = 5,
// [END_EXCLUDE]
setupBlock = {
// Before starting to measure, navigate to the UI to be measured
startActivityAndWait()
// click a button to launch the target activity.
// While we use resourceId here to find the button, you could also use
// accessibility info or button text content.
val launchRecyclerActivity = device.findObject(
By.res(packageName, "launchRecyclerActivity")
)
launchRecyclerActivity.click()
// wait until the activity is shown
device.wait(
Until.hasObject(By.clazz("$packageName.NonExportedRecyclerActivity")),
TimeUnit.SECONDS.toMillis(10)
)
}
) {
// [START_EXCLUDE]
val recycler = device.findObject(By.res(packageName, "recycler"))
// Set gesture margin to avoid triggering gesture navigation
// with input events from automation.
recycler.setGestureMargin(device.displayWidth / 5)
// Fling the recycler several times
repeat(3) { recycler.fling(Direction.DOWN) }
// [END_EXCLUDE]
}
}