Add support for baseline profiles.

This commit is contained in:
Clark
2023-03-09 14:27:03 -05:00
committed by Greyson Parrelli
parent 79a062c838
commit 04baa7925f
20 changed files with 37283 additions and 22 deletions

1
benchmark/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

View File

@@ -0,0 +1,81 @@
@file:Suppress("UnstableApiUsage")
import com.android.build.api.dsl.ManagedVirtualDevice
import org.gradle.api.JavaVersion
import org.gradle.kotlin.dsl.extra
val benchmarkLibs = the<org.gradle.accessors.dm.LibrariesForBenchmarkLibs>()
val signalBuildToolsVersion: String by extra
val signalCompileSdkVersion: String by extra
val signalTargetSdkVersion: Int by extra
val signalMinSdkVersion: Int by extra
val signalJavaVersion: JavaVersion by extra
plugins {
id("com.android.test")
id("android-constants")
id("org.jetbrains.kotlin.android")
}
android {
namespace = "org.signal.benchmark"
compileSdkVersion = signalCompileSdkVersion
compileOptions {
sourceCompatibility = signalJavaVersion
targetCompatibility = signalJavaVersion
}
kotlinOptions {
jvmTarget = "11"
}
defaultConfig {
minSdk = 23
targetSdk = signalTargetSdkVersion
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
missingDimensionStrategy("environment", "prod")
missingDimensionStrategy("distribution", "play")
}
buildTypes {
create("benchmark") {
isDebuggable = true
signingConfig = getByName("debug").signingConfig
matchingFallbacks += listOf("perf", "debug")
}
}
targetProjectPath = ":Signal-Android"
experimentalProperties["android.experimental.self-instrumenting"] = true
testOptions {
managedDevices {
devices {
create ("api31", ManagedVirtualDevice::class) {
device = "Pixel 6"
apiLevel = 31
systemImageSource = "aosp"
require64Bit = false
}
}
}
}
}
dependencies {
implementation(benchmarkLibs.androidx.test.ext.junit)
implementation(benchmarkLibs.espresso.core)
implementation(benchmarkLibs.uiautomator)
implementation(benchmarkLibs.androidx.benchmark.macro)
}
androidComponents {
beforeVariants(selector().all()) {
it.enabled = it.buildType == "benchmark"
}
}

View File

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

View File

@@ -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)
}
)
}

View File

@@ -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()
}
}
}