From dec2de647fbe80b3691cfc5ba7b3a9902e045651 Mon Sep 17 00:00:00 2001 From: Matthew Robertson Date: Thu, 22 May 2025 10:17:00 -0400 Subject: [PATCH] Add macrobenchmark module for sessions test app --- firebase-sessions/benchmark/README.md | 5 ++ .../benchmark/benchmark.gradle.kts | 63 +++++++++++++++++++ .../benchmark/src/main/AndroidManifest.xml | 17 +++++ .../benchmark/sessions/StartupBenchmark.kt | 42 +++++++++++++ .../test-app/src/main/AndroidManifest.xml | 8 ++- .../test-app/test-app.gradle.kts | 20 +++++- gradle/libs.versions.toml | 2 + subprojects.cfg | 1 + 8 files changed, 153 insertions(+), 5 deletions(-) create mode 100644 firebase-sessions/benchmark/README.md create mode 100644 firebase-sessions/benchmark/benchmark.gradle.kts create mode 100644 firebase-sessions/benchmark/src/main/AndroidManifest.xml create mode 100644 firebase-sessions/benchmark/src/main/kotlin/com/google/firebase/benchmark/sessions/StartupBenchmark.kt diff --git a/firebase-sessions/benchmark/README.md b/firebase-sessions/benchmark/README.md new file mode 100644 index 00000000000..13a9941c665 --- /dev/null +++ b/firebase-sessions/benchmark/README.md @@ -0,0 +1,5 @@ +# Firebase Sessions Macrobenchmark + +## Setup + +## Run diff --git a/firebase-sessions/benchmark/benchmark.gradle.kts b/firebase-sessions/benchmark/benchmark.gradle.kts new file mode 100644 index 00000000000..115e73c66ed --- /dev/null +++ b/firebase-sessions/benchmark/benchmark.gradle.kts @@ -0,0 +1,63 @@ +/* + * Copyright 2025 Google LLC + * + * 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 + * + * http://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. + */ + +plugins { + id("com.android.test") + id("org.jetbrains.kotlin.android") +} + +android { + val compileSdkVersion: Int by rootProject + val targetSdkVersion: Int by rootProject + + namespace = "com.google.firebase.benchmark.sessions" + compileSdk = compileSdkVersion + + defaultConfig { + targetSdk = targetSdkVersion + minSdk = 23 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + create("benchmark") { + isDebuggable = true + signingConfig = signingConfigs["debug"] + matchingFallbacks += "release" + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { jvmTarget = "1.8" } + + targetProjectPath = ":firebase-sessions:test-app" + experimentalProperties["android.experimental.self-instrumenting"] = true +} + +dependencies { + implementation(libs.androidx.test.junit) + implementation(libs.androidx.benchmark.macro) +} + +androidComponents { + beforeVariants(selector().all()) { variantBuilder -> + variantBuilder.enable = (variantBuilder.buildType == "benchmark") + } +} diff --git a/firebase-sessions/benchmark/src/main/AndroidManifest.xml b/firebase-sessions/benchmark/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..4f78f2c185d --- /dev/null +++ b/firebase-sessions/benchmark/src/main/AndroidManifest.xml @@ -0,0 +1,17 @@ + + + diff --git a/firebase-sessions/benchmark/src/main/kotlin/com/google/firebase/benchmark/sessions/StartupBenchmark.kt b/firebase-sessions/benchmark/src/main/kotlin/com/google/firebase/benchmark/sessions/StartupBenchmark.kt new file mode 100644 index 00000000000..fac6f1a4977 --- /dev/null +++ b/firebase-sessions/benchmark/src/main/kotlin/com/google/firebase/benchmark/sessions/StartupBenchmark.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2025 Google LLC + * + * 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 + * + * http://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.firebase.benchmark.sessions + +import androidx.benchmark.macro.StartupMode +import androidx.benchmark.macro.StartupTimingMetric +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 + +@RunWith(AndroidJUnit4::class) +class StartupBenchmark { + @get:Rule val benchmarkRule = MacrobenchmarkRule() + + @Test + fun startup() = + benchmarkRule.measureRepeated( + packageName = "com.google.firebase.testing.sessions", + metrics = listOf(StartupTimingMetric()), + iterations = 5, + startupMode = StartupMode.COLD, + ) { + pressHome() + startActivityAndWait() + } +} diff --git a/firebase-sessions/test-app/src/main/AndroidManifest.xml b/firebase-sessions/test-app/src/main/AndroidManifest.xml index 3e1f4840cb3..ea99dda43e0 100644 --- a/firebase-sessions/test-app/src/main/AndroidManifest.xml +++ b/firebase-sessions/test-app/src/main/AndroidManifest.xml @@ -51,6 +51,12 @@ android:name="firebase_sessions_sessions_restart_timeout" android:value="5" /> + + + + - -