benchmark: init

This commit is contained in:
Harsh Shandilya 2022-06-21 11:17:37 +05:30
parent d8d43a4c88
commit a66a915e16
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
12 changed files with 189 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="dev.msfjarvis.claw.android" />
</queries>
</manifest>

View file

@ -0,0 +1,36 @@
package dev.msfjarvis.claw.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 org.junit.Rule
import org.junit.Test
class BaselineProfileBenchmark {
@get:Rule val benchmarkRule = MacrobenchmarkRule()
@Test
fun startupNoCompilation() {
startup(CompilationMode.None())
}
@Test
fun startupBaselineProfile() {
startup(CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Require))
}
private fun startup(compilationMode: CompilationMode) {
benchmarkRule.measureRepeated(
packageName = PACKAGE_NAME,
metrics = listOf(StartupTimingMetric()),
iterations = 10,
startupMode = StartupMode.COLD,
compilationMode = compilationMode
) {
pressHome()
startActivityAndWait()
}
}
}

View file

@ -0,0 +1,27 @@
package dev.msfjarvis.claw.benchmark
import androidx.benchmark.macro.ExperimentalBaselineProfilesApi
import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ExperimentalBaselineProfilesApi
class BaselineProfileGenerator {
@get:Rule val baselineProfileRule = BaselineProfileRule()
private lateinit var device: UiDevice
@Before
fun setUp() {
val instrumentation = InstrumentationRegistry.getInstrumentation()
device = UiDevice.getInstance(instrumentation)
}
@Test
fun startup() =
baselineProfileRule.collectBaselineProfile(packageName = PACKAGE_NAME) {
tapNavigationDestinations(device)
}
}

View file

@ -0,0 +1,18 @@
package dev.msfjarvis.claw.benchmark
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
const val PACKAGE_NAME = "dev.msfjarvis.claw.android"
fun MacrobenchmarkScope.tapNavigationDestinations(device: UiDevice) {
startActivityAndWait()
device.run {
listOf("HOTTEST", "NEWEST", "SAVED").forEach { desc ->
findObject(By.desc(desc)).click()
waitForIdle()
}
}
device.waitForIdle()
}