Create proguard-rules.pro, disabling obfuscation. The BaselineProfileGenerator needs to run on an AOSP emulator. Classes in StartupBenchmark should run on a physical device to produce reliable data. The baseline-prof.txt file should be re-generated for each release. Change-Id: Iaceb4e5c6d2f927dc545454a44dea43951dfaf6dpull/2/head
parent
773b2640b3
commit
5b54858642
@ -0,0 +1,2 @@
|
||||
#Proguard rules for the `benchmark` build type.
|
||||
-dontobfuscate
|
@ -0,0 +1,26 @@
|
||||
# Keep `Companion` object fields of serializable classes.
|
||||
# This avoids serializer lookup through `getDeclaredClasses` as done for named companion objects.
|
||||
-if @kotlinx.serialization.Serializable class **
|
||||
-keepclassmembers class <1> {
|
||||
static <1>$Companion Companion;
|
||||
}
|
||||
|
||||
# Keep `serializer()` on companion objects (both default and named) of serializable classes.
|
||||
-if @kotlinx.serialization.Serializable class ** {
|
||||
static **$* *;
|
||||
}
|
||||
-keepclassmembers class <2>$<3> {
|
||||
kotlinx.serialization.KSerializer serializer(...);
|
||||
}
|
||||
|
||||
# Keep `INSTANCE.serializer()` of serializable objects.
|
||||
-if @kotlinx.serialization.Serializable class ** {
|
||||
public static ** INSTANCE;
|
||||
}
|
||||
-keepclassmembers class <1> {
|
||||
public static <1> INSTANCE;
|
||||
kotlinx.serialization.KSerializer serializer(...);
|
||||
}
|
||||
|
||||
# @Serializable and @Polymorphic are used at runtime for polymorphic serialization.
|
||||
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,55 @@
|
||||
plugins {
|
||||
id 'com.android.test'
|
||||
id 'org.jetbrains.kotlin.android'
|
||||
}
|
||||
|
||||
android {
|
||||
namespace 'com.google.samples.apps.nowinandroid.benchmark'
|
||||
compileSdk buildConfig.compileSdk
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdk 23
|
||||
targetSdk 31
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
// This benchmark buildType is used for benchmarking, and should function like your
|
||||
// release build (for example, with minification on). It's signed with a debug key
|
||||
// for easy local/CI testing.
|
||||
benchmark {
|
||||
debuggable true
|
||||
signingConfig debug.signingConfig
|
||||
matchingFallbacks = ['release']
|
||||
}
|
||||
}
|
||||
|
||||
targetProjectPath = ":app"
|
||||
experimentalProperties["android.experimental.self-instrumenting"] = true
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation libs.androidx.test.core
|
||||
implementation libs.androidx.test.espresso.core
|
||||
implementation libs.androidx.test.ext
|
||||
implementation libs.androidx.test.runner
|
||||
implementation libs.androidx.test.rules
|
||||
implementation libs.androidx.test.uiautomator
|
||||
implementation libs.androidx.benchmark.macro
|
||||
implementation libs.androidx.profileinstaller
|
||||
}
|
||||
|
||||
androidComponents {
|
||||
beforeVariants(selector().all()) {
|
||||
enabled = buildType == "benchmark"
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.samples.apps.nowinandroid.baselineprofile
|
||||
|
||||
import androidx.benchmark.macro.ExperimentalBaselineProfilesApi
|
||||
import androidx.benchmark.macro.junit4.BaselineProfileRule
|
||||
import androidx.test.uiautomator.By
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Generates a baseline profile which can be copied to `app/src/main/baseline-prof.txt`.
|
||||
*/
|
||||
@ExperimentalBaselineProfilesApi
|
||||
class BaselineProfileGenerator {
|
||||
@get:Rule val baselineProfileRule = BaselineProfileRule()
|
||||
|
||||
@Test
|
||||
fun startup() =
|
||||
baselineProfileRule.collectBaselineProfile(
|
||||
packageName = "com.google.samples.apps.nowinandroid"
|
||||
) {
|
||||
pressHome()
|
||||
// This block defines the app's critical user journey. Here we are interested in
|
||||
// optimizing for app startup. But you can also navigate and scroll
|
||||
// through your most important UI.
|
||||
startActivityAndWait()
|
||||
device.waitForIdle()
|
||||
listOf("Episodes", "Saved", "Following").forEach {
|
||||
device.run {
|
||||
findObject(By.text(it))
|
||||
.click()
|
||||
waitForIdle()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.samples.apps.nowinandroid.startup
|
||||
|
||||
import androidx.benchmark.macro.BaselineProfileMode.Disable
|
||||
import androidx.benchmark.macro.BaselineProfileMode.Require
|
||||
import androidx.benchmark.macro.CompilationMode
|
||||
import androidx.benchmark.macro.StartupMode
|
||||
import androidx.benchmark.macro.StartupMode.COLD
|
||||
import androidx.benchmark.macro.StartupMode.HOT
|
||||
import androidx.benchmark.macro.StartupMode.WARM
|
||||
import androidx.benchmark.macro.StartupTimingMetric
|
||||
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
|
||||
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
/**
|
||||
* Run this benchmark from Studio to see startup measurements, and captured system traces
|
||||
* for investigating your app's performance from a cold state.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4ClassRunner::class)
|
||||
class ColdStartupBenchmark : AbstractStartupBenchmark(COLD)
|
||||
|
||||
/**
|
||||
* Run this benchmark from Studio to see startup measurements, and captured system traces
|
||||
* for investigating your app's performance from a warm state.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4ClassRunner::class)
|
||||
class WarmStartupBenchmark : AbstractStartupBenchmark(WARM)
|
||||
|
||||
/**
|
||||
* Run this benchmark from Studio to see startup measurements, and captured system traces
|
||||
* for investigating your app's performance from a hot state.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4ClassRunner::class)
|
||||
class HotStartupBenchmark : AbstractStartupBenchmark(HOT)
|
||||
|
||||
/**
|
||||
* Base class for benchmarks with different startup modes.
|
||||
* Enables app startups from various states of baseline profile or [CompilationMode]s.
|
||||
*/
|
||||
abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) {
|
||||
@get:Rule
|
||||
val benchmarkRule = MacrobenchmarkRule()
|
||||
|
||||
@Test
|
||||
fun startupNoCompilation() = startup(CompilationMode.None())
|
||||
|
||||
@Test
|
||||
fun startupBaselineProfileDisabled() = startup(
|
||||
CompilationMode.Partial(baselineProfileMode = Disable, warmupIterations = 1)
|
||||
)
|
||||
|
||||
@Test
|
||||
fun startupBaselineProfile() = startup(CompilationMode.Partial(baselineProfileMode = Require))
|
||||
|
||||
@Test
|
||||
fun startupFullCompilation() = startup(CompilationMode.Full())
|
||||
|
||||
private fun startup(compilationMode: CompilationMode) = benchmarkRule.measureRepeated(
|
||||
packageName = "com.google.samples.apps.nowinandroid",
|
||||
metrics = listOf(StartupTimingMetric()),
|
||||
compilationMode = compilationMode,
|
||||
iterations = 10,
|
||||
startupMode = startupMode,
|
||||
setupBlock = {
|
||||
pressHome()
|
||||
}
|
||||
) {
|
||||
startActivityAndWait()
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
#Thu Feb 24 14:19:14 GMT 2022
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
Loading…
Reference in new issue