Android: Baseline profile generation

This creates a new benchmark module that is responsible for generating baseline profiles and testing them. As part of this commit a baseline-prof.txt file has been included to speed up launch times with the app in its current state. Later, profile generation can be automated and keep up with the app as it changes.
This commit is contained in:
Charles Lombardo
2022-12-09 12:13:34 -05:00
parent 61c10a5644
commit 974003888a
10 changed files with 4085 additions and 1 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<queries>
<package android:name="org.dolphinemu.dolphinemu.debug" />
</queries>
</manifest>

View File

@ -0,0 +1,43 @@
package com.dolphin.benchmark
import androidx.benchmark.macro.ExperimentalBaselineProfilesApi
import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import androidx.test.uiautomator.UiSelector
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@OptIn(ExperimentalBaselineProfilesApi::class)
@RunWith(AndroidJUnit4ClassRunner::class)
class BaselineProfileGenerator {
@get:Rule
val rule = BaselineProfileRule()
@Test
fun generate() = rule.collectBaselineProfile(
packageName = "org.dolphinemu.dolphinemu.benchmark",
profileBlock = {
pressHome()
startActivityAndWait()
// Dismiss analytics dialog due to issue with finding button
device.pressBack()
// Navigate through activities that don't require games
// TODO: Make all activities testable without having games available
// TODO: Use resource strings to support more languages
// Navigate to the Settings Activity
val settings = device.findObject(UiSelector().description("Settings"))
settings.clickAndWaitForNewWindow(30_000)
// Go through settings and to the User Data Activity
val config = device.findObject(UiSelector().textContains("Config"))
config.click()
val userData = device.findObject(UiSelector().textContains("User Data"))
userData.clickAndWaitForNewWindow(30_000)
},
)
}

View File

@ -0,0 +1,40 @@
package com.dolphin.benchmark
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 org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class StartupBenchmark {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()
@Test
fun startupBaselineProfileDisabled() = startup(
CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Disable, warmupIterations = 1)
)
@Test
fun startupBaselineProfile() = startup(
CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Require, warmupIterations = 1)
)
private fun startup(compilationMode: CompilationMode) = benchmarkRule.measureRepeated(
packageName = "org.dolphinemu.dolphinemu.benchmark",
metrics = listOf(StartupTimingMetric()),
iterations = 10,
compilationMode = compilationMode,
startupMode = StartupMode.COLD,
setupBlock = {
pressHome()
}
) {
startActivityAndWait()
}
}