mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-23 19:26:17 +00:00
Add support for baseline profiles.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
@file:OptIn(ExperimentalBaselineProfilesApi::class)
|
||||
|
||||
package org.thoughtcrime.benchmark
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import androidx.benchmark.macro.ExperimentalBaselineProfilesApi
|
||||
import androidx.benchmark.macro.junit4.BaselineProfileRule
|
||||
import androidx.test.uiautomator.By
|
||||
import androidx.test.uiautomator.Until
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* WARNING! THIS WILL WIPE YOUR SIGNAL INSTALL
|
||||
*
|
||||
* Test that generates a Baseline profile from a user journey. Our journey is:
|
||||
* - start the app
|
||||
* - open a conversation
|
||||
*/
|
||||
class BaselineProfileGenerator {
|
||||
@get:Rule
|
||||
val baselineProfileRule = BaselineProfileRule()
|
||||
|
||||
@Test
|
||||
fun startup() = baselineProfileRule.collectBaselineProfile(
|
||||
packageName = "org.thoughtcrime.securesms",
|
||||
profileBlock = {
|
||||
val setupIntent = Intent().apply {
|
||||
component = ComponentName("org.thoughtcrime.securesms", "org.signal.benchmark.BenchmarkSetupActivity")
|
||||
}
|
||||
startActivityAndWait(setupIntent)
|
||||
startActivityAndWait()
|
||||
device.findObject(By.textContains("Buddy")).click();
|
||||
device.wait(
|
||||
Until.hasObject(By.clazz("$packageName.conversation.ConversationActivity")),
|
||||
10000L
|
||||
)
|
||||
device.wait(Until.hasObject(By.textContains("Test")), 10_000L)
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package org.thoughtcrime.benchmark
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import androidx.benchmark.macro.CompilationMode
|
||||
import androidx.benchmark.macro.ExperimentalMetricApi
|
||||
import androidx.benchmark.macro.MacrobenchmarkScope
|
||||
import androidx.benchmark.macro.StartupMode
|
||||
import androidx.benchmark.macro.StartupTimingMetric
|
||||
import androidx.benchmark.macro.TraceSectionMetric
|
||||
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
|
||||
|
||||
/**
|
||||
* Macrobenchmark benchmarks for app startup performance.
|
||||
*
|
||||
* WARNING! THIS WILL WIPE YOUR SIGNAL INSTALL
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class StartupBenchmarks {
|
||||
@get:Rule
|
||||
val benchmarkRule = MacrobenchmarkRule()
|
||||
|
||||
@Test
|
||||
fun coldStartNone() {
|
||||
measureStartup(5, CompilationMode.None())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun coldStartBaselineProfile() {
|
||||
measureStartup(5, CompilationMode.Partial())
|
||||
}
|
||||
|
||||
private val fakeDataSetupBlock: MacrobenchmarkScope.() -> Unit = {
|
||||
val setupIntent = Intent().apply {
|
||||
component = ComponentName("org.thoughtcrime.securesms", "org.signal.benchmark.BenchmarkSetupActivity")
|
||||
}
|
||||
startActivityAndWait(setupIntent)
|
||||
|
||||
killProcess()
|
||||
dropKernelPageCache()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMetricApi::class)
|
||||
private fun measureStartup(iterations: Int, compilationMode: CompilationMode) {
|
||||
benchmarkRule.measureRepeated(
|
||||
packageName = "org.thoughtcrime.securesms",
|
||||
metrics = listOf(StartupTimingMetric(), TraceSectionMetric("ConversationListDataSource#load")),
|
||||
iterations = iterations,
|
||||
startupMode = StartupMode.COLD,
|
||||
compilationMode = compilationMode,
|
||||
setupBlock = fakeDataSetupBlock
|
||||
) {
|
||||
pressHome()
|
||||
startActivityAndWait()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user