Skip to content

Commit dec2de6

Browse files
committed
Add macrobenchmark module for sessions test app
1 parent 5db7bfb commit dec2de6

File tree

8 files changed

+153
-5
lines changed

8 files changed

+153
-5
lines changed

firebase-sessions/benchmark/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Firebase Sessions Macrobenchmark
2+
3+
## Setup
4+
5+
## Run
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
id("com.android.test")
19+
id("org.jetbrains.kotlin.android")
20+
}
21+
22+
android {
23+
val compileSdkVersion: Int by rootProject
24+
val targetSdkVersion: Int by rootProject
25+
26+
namespace = "com.google.firebase.benchmark.sessions"
27+
compileSdk = compileSdkVersion
28+
29+
defaultConfig {
30+
targetSdk = targetSdkVersion
31+
minSdk = 23
32+
33+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
34+
}
35+
36+
buildTypes {
37+
create("benchmark") {
38+
isDebuggable = true
39+
signingConfig = signingConfigs["debug"]
40+
matchingFallbacks += "release"
41+
}
42+
}
43+
44+
compileOptions {
45+
sourceCompatibility = JavaVersion.VERSION_1_8
46+
targetCompatibility = JavaVersion.VERSION_1_8
47+
}
48+
kotlinOptions { jvmTarget = "1.8" }
49+
50+
targetProjectPath = ":firebase-sessions:test-app"
51+
experimentalProperties["android.experimental.self-instrumenting"] = true
52+
}
53+
54+
dependencies {
55+
implementation(libs.androidx.test.junit)
56+
implementation(libs.androidx.benchmark.macro)
57+
}
58+
59+
androidComponents {
60+
beforeVariants(selector().all()) { variantBuilder ->
61+
variantBuilder.enable = (variantBuilder.buildType == "benchmark")
62+
}
63+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!--
2+
~ Copyright 2025 Google LLC
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
17+
<manifest />
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.benchmark.sessions
18+
19+
import androidx.benchmark.macro.StartupMode
20+
import androidx.benchmark.macro.StartupTimingMetric
21+
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
22+
import androidx.test.ext.junit.runners.AndroidJUnit4
23+
import org.junit.Rule
24+
import org.junit.Test
25+
import org.junit.runner.RunWith
26+
27+
@RunWith(AndroidJUnit4::class)
28+
class StartupBenchmark {
29+
@get:Rule val benchmarkRule = MacrobenchmarkRule()
30+
31+
@Test
32+
fun startup() =
33+
benchmarkRule.measureRepeated(
34+
packageName = "com.google.firebase.testing.sessions",
35+
metrics = listOf(StartupTimingMetric()),
36+
iterations = 5,
37+
startupMode = StartupMode.COLD,
38+
) {
39+
pressHome()
40+
startActivityAndWait()
41+
}
42+
}

firebase-sessions/test-app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@
5151
android:name="firebase_sessions_sessions_restart_timeout"
5252
android:value="5" />
5353

54+
<profileable
55+
android:shell="true"
56+
tools:targetApi="29" />
57+
58+
<receiver android:name=".CrashBroadcastReceiver" />
59+
5460
<receiver
5561
android:exported="false"
5662
android:name="CrashWidgetProvider"
@@ -63,8 +69,6 @@
6369
android:resource="@xml/homescreen_widget" />
6470
</receiver>
6571

66-
<receiver android:name=".CrashBroadcastReceiver" />
67-
6872
<service
6973
android:enabled="true"
7074
android:exported="false"

firebase-sessions/test-app/test-app.gradle.kts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ android {
3535

3636
namespace = "com.google.firebase.testing.sessions"
3737
compileSdk = compileSdkVersion
38-
buildFeatures.buildConfig = true
38+
3939
defaultConfig {
4040
applicationId = "com.google.firebase.testing.sessions"
4141
minSdk = minSdkVersion
@@ -50,15 +50,29 @@ android {
5050
buildConfigField(
5151
"boolean",
5252
"SHOULD_CRASH_APP",
53-
project.hasProperty("triggerCrashes").toString()
53+
project.hasProperty("triggerCrashes").toString(),
5454
)
5555
}
56+
57+
buildTypes {
58+
create("benchmark") {
59+
initWith(buildTypes["release"])
60+
signingConfig = signingConfigs["debug"]
61+
matchingFallbacks += "release"
62+
isDebuggable = false
63+
}
64+
}
65+
5666
compileOptions {
5767
sourceCompatibility = JavaVersion.VERSION_1_8
5868
targetCompatibility = JavaVersion.VERSION_1_8
5969
}
6070
kotlinOptions { jvmTarget = "1.8" }
61-
buildFeatures { viewBinding = true }
71+
72+
buildFeatures {
73+
buildConfig = true
74+
viewBinding = true
75+
}
6276
}
6377

6478
dependencies {

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ appcompat = "1.7.0"
1111
autoValueParcel = "0.2.6"
1212
autovalue = "1.10.1"
1313
awaitility = "3.1.0"
14+
benchmarkMacro = "1.3.4"
1415
browser = "1.3.0"
1516
cardview = "1.0.0"
1617
checkerQual = "2.5.2"
@@ -86,6 +87,7 @@ android-lint-tests = { module = "com.android.tools.lint:lint-tests", version.ref
8687
android-lint-testutils = { module = "com.android.tools:testutils", version.ref = "android-lint" }
8788
androidx-annotation = { module = "androidx.annotation:annotation", version = "1.5.0" }
8889
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
90+
androidx-benchmark-macro = { group = "androidx.benchmark", name = "benchmark-macro-junit4", version.ref = "benchmarkMacro" }
8991
androidx-browser = { module = "androidx.browser:browser", version.ref = "browser" }
9092
androidx-cardview = { module = "androidx.cardview:cardview", version.ref = "cardview" }
9193
androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintlayout" }

subprojects.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ firebase-perf:ktx
5757
firebase-perf:dev-app
5858
firebase-perf:e2e-app
5959
firebase-sessions
60+
firebase-sessions:benchmark
6061
firebase-sessions:test-app
6162
firebase-storage
6263
firebase-storage:ktx

0 commit comments

Comments
 (0)