From e63586d4d937398e39b08b893269b548f567b032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Mlynari=C4=8D?= Date: Mon, 27 Jun 2022 16:52:46 +0200 Subject: [PATCH] Use flavor and buildType to properly define package name Change-Id: Ieb297672ef9d7b2da86e7cbb133b537ece27fd9f --- benchmark/build.gradle.kts | 9 ++++++- .../google/samples/apps/nowinandroid/Utils.kt | 25 +++++++++++++++++++ .../BaselineProfileGenerator.kt | 5 ++-- .../nowinandroid/startup/StartupBenchmark.kt | 3 ++- 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 benchmark/src/main/java/com/google/samples/apps/nowinandroid/Utils.kt diff --git a/benchmark/build.gradle.kts b/benchmark/build.gradle.kts index f59e32dd3..fab2055e7 100644 --- a/benchmark/build.gradle.kts +++ b/benchmark/build.gradle.kts @@ -13,6 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import com.google.samples.apps.nowinandroid.Flavor +import com.google.samples.apps.nowinandroid.FlavorDimension +import com.google.samples.apps.nowinandroid.configureFlavors plugins { id("nowinandroid.android.test") @@ -25,7 +28,6 @@ android { defaultConfig { minSdk = 23 testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - missingDimensionStrategy("contentType", "demo") } buildTypes { @@ -40,6 +42,11 @@ android { } } + // Use the same flavor dimensions as the application to allow generating Baseline Profiles on prod, + // which is more close to what will be shipped to users (no fake data), but has ability to run the + // benchmarks on demo, so we benchmark on stable data. + configureFlavors(this) + targetProjectPath = ":app" experimentalProperties["android.experimental.self-instrumenting"] = true } diff --git a/benchmark/src/main/java/com/google/samples/apps/nowinandroid/Utils.kt b/benchmark/src/main/java/com/google/samples/apps/nowinandroid/Utils.kt new file mode 100644 index 000000000..5db7b5c91 --- /dev/null +++ b/benchmark/src/main/java/com/google/samples/apps/nowinandroid/Utils.kt @@ -0,0 +1,25 @@ +/* + * 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 + +import com.google.samples.apps.nowinandroid.benchmark.BuildConfig + +/** + * Convenience parameter to use proper package name with regards to build type and build flavor. + */ +const val PACKAGE_NAME = + "com.google.samples.apps.nowinandroid.${BuildConfig.FLAVOR}.${BuildConfig.BUILD_TYPE}" diff --git a/benchmark/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.kt b/benchmark/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.kt index 2fdc28bad..450524cc2 100644 --- a/benchmark/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.kt +++ b/benchmark/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.kt @@ -20,6 +20,7 @@ import androidx.benchmark.macro.ExperimentalBaselineProfilesApi import androidx.benchmark.macro.junit4.BaselineProfileRule import androidx.test.uiautomator.By import androidx.test.uiautomator.Direction +import com.google.samples.apps.nowinandroid.PACKAGE_NAME import org.junit.Rule import org.junit.Test @@ -32,9 +33,7 @@ class BaselineProfileGenerator { @Test fun startup() = - baselineProfileRule.collectBaselineProfile( - packageName = "com.google.samples.apps.nowinandroid.demo.benchmark" - ) { + baselineProfileRule.collectBaselineProfile(PACKAGE_NAME) { 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 diff --git a/benchmark/src/main/java/com/google/samples/apps/nowinandroid/startup/StartupBenchmark.kt b/benchmark/src/main/java/com/google/samples/apps/nowinandroid/startup/StartupBenchmark.kt index 49194ed4c..b33acacc7 100644 --- a/benchmark/src/main/java/com/google/samples/apps/nowinandroid/startup/StartupBenchmark.kt +++ b/benchmark/src/main/java/com/google/samples/apps/nowinandroid/startup/StartupBenchmark.kt @@ -26,6 +26,7 @@ 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 com.google.samples.apps.nowinandroid.PACKAGE_NAME import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -74,7 +75,7 @@ abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) { fun startupFullCompilation() = startup(CompilationMode.Full()) private fun startup(compilationMode: CompilationMode) = benchmarkRule.measureRepeated( - packageName = "com.google.samples.apps.nowinandroid", + packageName = PACKAGE_NAME, metrics = listOf(StartupTimingMetric()), compilationMode = compilationMode, iterations = 10,