Skip to content

Add macrobenchmark module for sessions test app #6982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions firebase-sessions/benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Firebase Sessions Macrobenchmark

## Setup

## Run
63 changes: 63 additions & 0 deletions firebase-sessions/benchmark/benchmark.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
}
17 changes: 17 additions & 0 deletions firebase-sessions/benchmark/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!--
~ 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.
-->

<manifest />
Original file line number Diff line number Diff line change
@@ -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()
}
}
8 changes: 6 additions & 2 deletions firebase-sessions/test-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -51,6 +51,12 @@
android:name="firebase_sessions_sessions_restart_timeout"
android:value="5" />

<profileable
android:shell="true"
tools:targetApi="29" />

<receiver android:name=".CrashBroadcastReceiver" />

<receiver
android:exported="false"
android:name="CrashWidgetProvider"
@@ -63,8 +69,6 @@
android:resource="@xml/homescreen_widget" />
</receiver>

<receiver android:name=".CrashBroadcastReceiver" />

<service
android:enabled="true"
android:exported="false"
20 changes: 17 additions & 3 deletions firebase-sessions/test-app/test-app.gradle.kts
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ android {

namespace = "com.google.firebase.testing.sessions"
compileSdk = compileSdkVersion
buildFeatures.buildConfig = true

defaultConfig {
applicationId = "com.google.firebase.testing.sessions"
minSdk = minSdkVersion
@@ -50,15 +50,29 @@ android {
buildConfigField(
"boolean",
"SHOULD_CRASH_APP",
project.hasProperty("triggerCrashes").toString()
project.hasProperty("triggerCrashes").toString(),
)
}

buildTypes {
create("benchmark") {
initWith(buildTypes["release"])
signingConfig = signingConfigs["debug"]
matchingFallbacks += "release"
isDebuggable = false
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions { jvmTarget = "1.8" }
buildFeatures { viewBinding = true }

buildFeatures {
buildConfig = true
viewBinding = true
}
}

dependencies {
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ appcompat = "1.7.0"
autoValueParcel = "0.2.6"
autovalue = "1.10.1"
awaitility = "3.1.0"
benchmarkMacro = "1.3.4"
browser = "1.3.0"
cardview = "1.0.0"
checkerQual = "2.5.2"
@@ -86,6 +87,7 @@ android-lint-tests = { module = "com.android.tools.lint:lint-tests", version.ref
android-lint-testutils = { module = "com.android.tools:testutils", version.ref = "android-lint" }
androidx-annotation = { module = "androidx.annotation:annotation", version = "1.5.0" }
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
androidx-benchmark-macro = { group = "androidx.benchmark", name = "benchmark-macro-junit4", version.ref = "benchmarkMacro" }
androidx-browser = { module = "androidx.browser:browser", version.ref = "browser" }
androidx-cardview = { module = "androidx.cardview:cardview", version.ref = "cardview" }
androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintlayout" }
1 change: 1 addition & 0 deletions subprojects.cfg
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@ firebase-perf:ktx
firebase-perf:dev-app
firebase-perf:e2e-app
firebase-sessions
firebase-sessions:benchmark
firebase-sessions:test-app
firebase-storage
firebase-storage:ktx