How to measure screen transition times in Android with Macrobenchmark

43 Views Asked by At

On Android we can write Macrobenchmark tests, to measure app startup and frame timing.

However I'm not sure how to use this to measure screen transition times.

According to this page, that's one of the included areas.

Normally I would use 2 variables and find the time difference.

However the idea of using Macrobenchmark tests as a separated process to run the app, was to write performance tests while treating the app as a black box.

Ideally I wouldn't need to modify the app code just to define sections (we have a Trace.beginSection and Trace.endSection methods).

Do I really need to worry on where to place them? Like first line on the viewModel for click events, and last line in the composable views, to define a section matching a screen transition. I hope not.

Then I tried this:

@Test
fun welcomeToChooseChannels() = benchmarkRule.measureRepeated(
    packageName = "my.demo.project",
    metrics = listOf(
        StartupTimingMetric(),
        FrameTimingMetric(),
        TraceSectionMetric("welcomeToChooseChannels")
    ),
    iterations = 3,
    startupMode = StartupMode.COLD,
    setupBlock = {
        clearAppData()
        pressHome()
    }
) {
    startActivityAndWait()

    device.wait(Until.hasObject(By.text("GET STARTED")), 5_000)

    Trace.beginSection("welcomeToChooseChannels")

    device
        .findObject(By.text("GET STARTED"))
        .click()

    // Button is shown after channels are fetched
    device.wait(Until.hasObject(By.text("Continue")), 5_000)

    device.waitForIdle()

    Trace.endSection()
}

The idea is to define the section on the Macrobenchmark test, and not in the app itself.

But it didn't work. Why?

Any insight on how to measure screen transitions is much appreciated.

0

There are 0 best solutions below