From a6df1572d986d6c4050cc12ec77e8b9e534a7854 Mon Sep 17 00:00:00 2001 From: Katherine Kuan <843428+kkuan2011@users.noreply.github.com> Date: Wed, 19 Aug 2026 00:43:36 +0000 Subject: [PATCH 01/11] Migrate Performance (Baseline Profiles, Benchmarking, JankStats, Launch Time) snippets --- gradle/libs.versions.toml | 6 ++ misc/build.gradle.kts | 7 ++ .../BaselineProfilesOverview.kt | 70 ++++++++++++++ .../MeasureBaselineProfile.kt | 95 +++++++++++++++++++ .../benchmarking/MacrobenchmarkOverview.kt | 55 +++++++++++ .../performance/jankstats/JankStats.kt | 35 +++++++ .../startupprofiles/DexLayoutOptimizations.kt | 62 ++++++++++++ .../snippets/performance/vitals/LaunchTime.kt | 82 ++++++++++++++++ 8 files changed, 412 insertions(+) create mode 100644 misc/src/main/java/com/example/snippets/performance/baselineprofiles/BaselineProfilesOverview.kt create mode 100644 misc/src/main/java/com/example/snippets/performance/baselineprofiles/MeasureBaselineProfile.kt create mode 100644 misc/src/main/java/com/example/snippets/performance/benchmarking/MacrobenchmarkOverview.kt create mode 100644 misc/src/main/java/com/example/snippets/performance/jankstats/JankStats.kt create mode 100644 misc/src/main/java/com/example/snippets/performance/startupprofiles/DexLayoutOptimizations.kt create mode 100644 misc/src/main/java/com/example/snippets/performance/vitals/LaunchTime.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 39a34593d..61f35ac8a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,6 +6,7 @@ androidGradlePlugin = "9.3.1" androidx-activity-compose = "1.13.0" androidx-appcompat = "1.7.1" androidx-appfunctions = "1.0.0-alpha10" +androidx-benchmark = "1.3.3" androidx-cameraX = "1.6.1" androidx-car = "1.7.0" androidx-compose-bom = "2026.09.00" @@ -27,6 +28,7 @@ androidx-glance-appwidget = "1.3.0-alpha02" androidx-lifecycle-compose = "2.11.0" androidx-lifecycle-runtime-compose = "2.11.0" androidx-lifecycle-viewmodel-navigation3 = "2.11.0" +androidx-metrics = "1.0.0-beta01" androidx-navigation = "2.9.8" androidx-navigation3 = "1.2.0-beta01" androidx-paging = "3.5.0" @@ -35,6 +37,7 @@ androidx-test = "1.7.0" androidx-test-core-ktx = "1.7.0" androidx-test-espresso = "3.7.0" androidx-test-junit = "1.3.0" +androidx-uiautomator = "2.3.0" androidx-window = "1.6.0-alpha05" androidx-window-core = "1.5.1" androidx-window-java = "1.5.1" @@ -145,6 +148,7 @@ androidx-activity-ktx = { module = "androidx.activity:activity-ktx", version.ref androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" } androidx-appfunctions = { module = "androidx.appfunctions:appfunctions", version.ref = "androidx-appfunctions" } androidx-appfunctions-compiler = { module = "androidx.appfunctions:appfunctions-compiler", version.ref = "androidx-appfunctions" } +androidx-benchmark-macro-junit4 = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "androidx-benchmark" } androidx-camera-camera2 = { module = "androidx.camera:camera-camera2", version.ref = "androidx-cameraX" } androidx-camera-compose = { module = "androidx.camera:camera-compose", version.ref = "androidx-cameraX" } androidx-camera-core = { module = "androidx.camera:camera-core", version.ref = "androidx-cameraX" } @@ -231,6 +235,7 @@ androidx-media3-session = { module = "androidx.media3:media3-session", version.r androidx-media3-ui = { module = "androidx.media3:media3-ui", version.ref = "media3Ui" } androidx-media3-ui-compose = { module = "androidx.media3:media3-ui-compose", version.ref = "media3Ui" } androidx-media3-ui-compose-material3 = { module = "androidx.media3:media3-ui-compose-material3", version.ref = "media3Ui" } +androidx-metrics-performance = { module = "androidx.metrics:metrics-performance", version.ref = "androidx-metrics" } androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "androidx-navigation" } androidx-navigation3-runtime = { module = "androidx.navigation3:navigation3-runtime", version.ref = "androidx-navigation3" } androidx-navigation3-ui = { module = "androidx.navigation3:navigation3-ui", version.ref = "androidx-navigation3" } @@ -265,6 +270,7 @@ androidx-test-core-ktx = { module = "androidx.test:core-ktx", version.ref = "and androidx-test-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "androidx-test-espresso" } androidx-test-ext-junit = { module = "androidx.test.ext:junit", version.ref = "androidx-test-junit" } androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidx-test" } +androidx-uiautomator = { module = "androidx.test.uiautomator:uiautomator", version.ref = "androidx-uiautomator" } androidx-tiles = { module = "androidx.wear.tiles:tiles", version.ref = "tiles" } androidx-tiles-renderer = { module = "androidx.wear.tiles:tiles-renderer", version.ref = "tiles" } androidx-tiles-testing = { module = "androidx.wear.tiles:tiles-testing", version.ref = "tiles" } diff --git a/misc/build.gradle.kts b/misc/build.gradle.kts index 6b2374365..87705b094 100644 --- a/misc/build.gradle.kts +++ b/misc/build.gradle.kts @@ -82,6 +82,13 @@ dependencies { implementation(libs.engage.core) + implementation(libs.androidx.metrics.performance) + implementation(libs.androidx.benchmark.macro.junit4) + implementation(libs.androidx.uiautomator) + implementation(libs.junit) + implementation(libs.androidx.test.ext.junit) + implementation(libs.androidx.test.runner) + testImplementation(libs.junit) testImplementation(kotlin("test")) androidTestImplementation(libs.androidx.test.ext.junit) diff --git a/misc/src/main/java/com/example/snippets/performance/baselineprofiles/BaselineProfilesOverview.kt b/misc/src/main/java/com/example/snippets/performance/baselineprofiles/BaselineProfilesOverview.kt new file mode 100644 index 000000000..0ad796c3d --- /dev/null +++ b/misc/src/main/java/com/example/snippets/performance/baselineprofiles/BaselineProfilesOverview.kt @@ -0,0 +1,70 @@ +/* + * Copyright 2026 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.example.snippets.performance.baselineprofiles + +import androidx.benchmark.macro.MacrobenchmarkScope +import androidx.benchmark.macro.junit4.BaselineProfileRule +import androidx.test.uiautomator.Direction +import org.junit.Rule +import org.junit.Test + +private const val PACKAGE_NAME = "com.example.app" + +// [START android_performance_baselineprofiles_overview_generator] +class BaselineProfileGenerator { + @get:Rule + val baselineProfileRule = BaselineProfileRule() + + @Test + fun appStartupAndUserJourneys() { + baselineProfileRule.collect(packageName = PACKAGE_NAME) { + uiAutomator { + // App startup journey. + startApp(PACKAGE_NAME) + + // Find and click elements using the new DSL + onElement { textAsString() == "COMPOSE LAZYLIST" }.click() + onElement { viewIdResourceName == "myLazyColumn" }.also { + it.fling(Direction.DOWN) + it.fling(Direction.UP) + } + pressBack() + } + } + } +} +// [END android_performance_baselineprofiles_overview_generator] + +private class OverviewElementScope { + val viewIdResourceName: String = "" + fun textAsString(): String = "" +} + +private class OverviewElement { + fun click() {} + fun fling(direction: Direction) {} +} + +private class OverviewUiAutomatorScope { + fun startApp(packageName: String) {} + fun onElement(block: OverviewElementScope.() -> Boolean): OverviewElement = OverviewElement() + fun pressBack() {} +} + +private fun MacrobenchmarkScope.uiAutomator(block: OverviewUiAutomatorScope.() -> Unit) { + OverviewUiAutomatorScope().block() +} diff --git a/misc/src/main/java/com/example/snippets/performance/baselineprofiles/MeasureBaselineProfile.kt b/misc/src/main/java/com/example/snippets/performance/baselineprofiles/MeasureBaselineProfile.kt new file mode 100644 index 000000000..696beb27f --- /dev/null +++ b/misc/src/main/java/com/example/snippets/performance/baselineprofiles/MeasureBaselineProfile.kt @@ -0,0 +1,95 @@ +/* + * Copyright 2026 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.example.snippets.performance.baselineprofiles + +import androidx.benchmark.macro.BaselineProfileMode +import androidx.benchmark.macro.CompilationMode +import androidx.benchmark.macro.MacrobenchmarkScope +import androidx.benchmark.macro.StartupMode +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 + +// [START android_performance_baselineprofiles_measure_compilation_modes] +@RunWith(AndroidJUnit4ClassRunner::class) +class ColdStartupBenchmark { + @get:Rule + val benchmarkRule = MacrobenchmarkRule() + + // No ahead-of-time (AOT) compilation at all. Represents performance of a + // fresh install on a user's device if you don't enable Baseline Profiles— + // generally the worst case performance. + @Test + fun startupNoCompilation() = startup(CompilationMode.None()) + + // Partial pre-compilation with Baseline Profiles. Represents performance of + // a fresh install on a user's device. + @Test + fun startupPartialWithBaselineProfiles() = + startup(CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Require)) + + // Partial pre-compilation with some just-in-time (JIT) compilation. + // Represents performance after some app usage. + @Test + fun startupPartialCompilation() = startup( + CompilationMode.Partial( + baselineProfileMode = BaselineProfileMode.Disable, + warmupIterations = 3 + ) + ) + + // Full pre-compilation. Generally not representative of real user + // experience, but can yield more stable performance metrics by removing + // noise from JIT compilation within benchmark runs. + @Test + fun startupFullCompilation() = startup(CompilationMode.Full()) + + private fun startup(compilationMode: CompilationMode) = benchmarkRule.measureRepeated( + packageName = "com.example.macrobenchmark.target", + metrics = listOf(StartupTimingMetric()), + compilationMode = compilationMode, + iterations = 10, + startupMode = StartupMode.COLD, + setupBlock = { + pressHome() + } + ) { + uiAutomator { + startApp(packageName) + onElement(5_000) { viewIdResourceName == "my-content" } + } + } +} +// [END android_performance_baselineprofiles_measure_compilation_modes] + +private class MeasureElementScope { + val viewIdResourceName: String = "" +} + +private class MeasureElement + +private class MeasureUiAutomatorScope { + fun startApp(packageName: String) {} + fun onElement(timeout: Long = 0L, block: MeasureElementScope.() -> Boolean): MeasureElement = MeasureElement() +} + +private fun MacrobenchmarkScope.uiAutomator(block: MeasureUiAutomatorScope.() -> Unit) { + MeasureUiAutomatorScope().block() +} diff --git a/misc/src/main/java/com/example/snippets/performance/benchmarking/MacrobenchmarkOverview.kt b/misc/src/main/java/com/example/snippets/performance/benchmarking/MacrobenchmarkOverview.kt new file mode 100644 index 000000000..26e63cdf3 --- /dev/null +++ b/misc/src/main/java/com/example/snippets/performance/benchmarking/MacrobenchmarkOverview.kt @@ -0,0 +1,55 @@ +/* + * Copyright 2026 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.example.snippets.performance.benchmarking + +import androidx.benchmark.macro.FrameTimingMetric +import androidx.benchmark.macro.StartupMode +import androidx.benchmark.macro.junit4.MacrobenchmarkRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import androidx.test.uiautomator.By +import androidx.test.uiautomator.Direction +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +// [START android_performance_macrobenchmark_compose_scroll] +@LargeTest +@RunWith(AndroidJUnit4::class) +class ComposeScrollBenchmark { + @get:Rule + val benchmarkRule = MacrobenchmarkRule() + + @Test + fun scrollLazyColumn() = benchmarkRule.measureRepeated( + packageName = "com.example.compose.app", + metrics = listOf(FrameTimingMetric()), + iterations = 5, + startupMode = StartupMode.WARM, + setupBlock = { pressHome() } + ) { + startActivityAndWait() + + // Find the Compose node using the testTag defined in your app + val lazyColumn = device.findObject(By.res("my_lazy_column")) + + // Simulate a scroll gesture to measure FrameTimingMetric + lazyColumn.setGestureMargin(device.displayWidth / 5) + lazyColumn.fling(Direction.DOWN) + } +} +// [END android_performance_macrobenchmark_compose_scroll] diff --git a/misc/src/main/java/com/example/snippets/performance/jankstats/JankStats.kt b/misc/src/main/java/com/example/snippets/performance/jankstats/JankStats.kt new file mode 100644 index 000000000..c3b718d32 --- /dev/null +++ b/misc/src/main/java/com/example/snippets/performance/jankstats/JankStats.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2026 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.example.snippets.performance.jankstats + +import android.view.View +import androidx.activity.ComponentActivity +import androidx.metrics.performance.PerformanceMetricsState + +private class JankStatsActivity : ComponentActivity() { + private lateinit var binding: MyBinding + + private class MyBinding(val root: View) + + private fun setupJankStats() { + // [START android_performance_jankstats_state_holder] + val metricsStateHolder = PerformanceMetricsState.getHolderForHierarchy(binding.root) + // ... + metricsStateHolder.state?.putState("Activity", javaClass.simpleName) + // [END android_performance_jankstats_state_holder] + } +} diff --git a/misc/src/main/java/com/example/snippets/performance/startupprofiles/DexLayoutOptimizations.kt b/misc/src/main/java/com/example/snippets/performance/startupprofiles/DexLayoutOptimizations.kt new file mode 100644 index 000000000..e7a0b3256 --- /dev/null +++ b/misc/src/main/java/com/example/snippets/performance/startupprofiles/DexLayoutOptimizations.kt @@ -0,0 +1,62 @@ +/* + * Copyright 2026 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.example.snippets.performance.startupprofiles + +import android.content.Intent +import androidx.benchmark.macro.MacrobenchmarkScope +import androidx.benchmark.macro.junit4.BaselineProfileRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +// [START android_performance_startupprofiles_generator] +@RunWith(AndroidJUnit4::class) +@LargeTest +class BaselineProfileGenerator { + + @get:Rule + val rule = BaselineProfileRule() + + @Test + fun generate() { + rule.collect( + packageName = "com.example.app", + includeInStartupProfile = true + ) { + uiAutomator { + // Launch directly into the NEWS_FEED using startActivityIntent + startIntent( + Intent().apply { + setPackage(packageName) + setAction("com.example.app.NEWS_FEED") + } + ) + } + } + } +} +// [END android_performance_startupprofiles_generator] + +private class UiAutomatorScope(val packageName: String) { + fun startIntent(intent: Intent) {} +} + +private fun MacrobenchmarkScope.uiAutomator(block: UiAutomatorScope.() -> Unit) { + UiAutomatorScope(packageName).block() +} diff --git a/misc/src/main/java/com/example/snippets/performance/vitals/LaunchTime.kt b/misc/src/main/java/com/example/snippets/performance/vitals/LaunchTime.kt new file mode 100644 index 000000000..752c0fdfa --- /dev/null +++ b/misc/src/main/java/com/example/snippets/performance/vitals/LaunchTime.kt @@ -0,0 +1,82 @@ +/* + * Copyright 2026 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.example.snippets.performance.vitals + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.lifecycle.lifecycleScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch + +private object LaunchTimeSnippet { + // [START android_performance_launch_time_fully_drawn_reporter] + class MainActivity : ComponentActivity() { + + sealed interface ActivityState { + data object LOADING : ActivityState + data object LOADED : ActivityState + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContent { + var activityState by remember { + mutableStateOf(ActivityState.LOADING as ActivityState) + } + fullyDrawnReporter.addOnReportDrawnListener { + activityState = ActivityState.LOADED + } + ReportFullyDrawnTheme { + when(activityState) { + is ActivityState.LOADING -> { + // Display the loading UI. + } + is ActivityState.LOADED -> { + // Display the full UI. + } + } + } + SideEffect { + fullyDrawnReporter.addReporter() + lifecycleScope.launch(Dispatchers.IO) { + // Perform the background operation. + fullyDrawnReporter.removeReporter() + } + fullyDrawnReporter.addReporter() + lifecycleScope.launch(Dispatchers.IO) { + // Perform the background operation. + fullyDrawnReporter.removeReporter() + } + } + } + } + } + // [END android_performance_launch_time_fully_drawn_reporter] +} + +@Composable +private fun ReportFullyDrawnTheme(content: @Composable () -> Unit) { + content() +} From 9bfbeda362c01b5b07471aa3f200a132e8fd842e Mon Sep 17 00:00:00 2001 From: Peng Quah Date: Mon, 31 Aug 2026 17:45:50 -0400 Subject: [PATCH 02/11] Update performance file structure for running tests and fix snippet initialization crashes - Upgrade androidx-benchmark to 1.4.1 and androidx-uiautomator to 2.4.0. - Relocate benchmarking tests from production source (src/main) to the test source set (src/androidTest). - Fix startup crash by making `SplitInitializer` a static inner class in `ActivityEmbeddingJavaSnippets.java`. - Update `AndroidManifest.xml` to correctly reference nested initializer classes using the `$` separator. - Adopt the new UI Automator 2.4.0 in `BaselineProfilesOverview.kt`. --- gradle/libs.versions.toml | 4 +-- misc/build.gradle.kts | 4 +-- .../BaselineProfilesOverview.kt | 25 +++---------------- .../MeasureBaselineProfile.kt | 17 +------------ .../benchmarking/MacrobenchmarkOverview.kt | 0 .../startupprofiles/DexLayoutOptimizations.kt | 0 misc/src/main/AndroidManifest.xml | 4 +-- .../ActivityEmbeddingJavaSnippets.java | 2 +- 8 files changed, 11 insertions(+), 45 deletions(-) rename misc/src/{main => androidTest}/java/com/example/snippets/performance/baselineprofiles/BaselineProfilesOverview.kt (71%) rename misc/src/{main => androidTest}/java/com/example/snippets/performance/baselineprofiles/MeasureBaselineProfile.kt (86%) rename misc/src/{main => androidTest}/java/com/example/snippets/performance/benchmarking/MacrobenchmarkOverview.kt (100%) rename misc/src/{main => androidTest}/java/com/example/snippets/performance/startupprofiles/DexLayoutOptimizations.kt (100%) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 61f35ac8a..96af3d932 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,7 +6,7 @@ androidGradlePlugin = "9.3.1" androidx-activity-compose = "1.13.0" androidx-appcompat = "1.7.1" androidx-appfunctions = "1.0.0-alpha10" -androidx-benchmark = "1.3.3" +androidx-benchmark = "1.4.1" androidx-cameraX = "1.6.1" androidx-car = "1.7.0" androidx-compose-bom = "2026.09.00" @@ -37,7 +37,7 @@ androidx-test = "1.7.0" androidx-test-core-ktx = "1.7.0" androidx-test-espresso = "3.7.0" androidx-test-junit = "1.3.0" -androidx-uiautomator = "2.3.0" +androidx-uiautomator = "2.4.0" androidx-window = "1.6.0-alpha05" androidx-window-core = "1.5.1" androidx-window-java = "1.5.1" diff --git a/misc/build.gradle.kts b/misc/build.gradle.kts index 87705b094..0c299b619 100644 --- a/misc/build.gradle.kts +++ b/misc/build.gradle.kts @@ -83,8 +83,8 @@ dependencies { implementation(libs.engage.core) implementation(libs.androidx.metrics.performance) - implementation(libs.androidx.benchmark.macro.junit4) - implementation(libs.androidx.uiautomator) + androidTestImplementation(libs.androidx.benchmark.macro.junit4) + androidTestImplementation(libs.androidx.uiautomator) implementation(libs.junit) implementation(libs.androidx.test.ext.junit) implementation(libs.androidx.test.runner) diff --git a/misc/src/main/java/com/example/snippets/performance/baselineprofiles/BaselineProfilesOverview.kt b/misc/src/androidTest/java/com/example/snippets/performance/baselineprofiles/BaselineProfilesOverview.kt similarity index 71% rename from misc/src/main/java/com/example/snippets/performance/baselineprofiles/BaselineProfilesOverview.kt rename to misc/src/androidTest/java/com/example/snippets/performance/baselineprofiles/BaselineProfilesOverview.kt index 0ad796c3d..283db7d6f 100644 --- a/misc/src/main/java/com/example/snippets/performance/baselineprofiles/BaselineProfilesOverview.kt +++ b/misc/src/androidTest/java/com/example/snippets/performance/baselineprofiles/BaselineProfilesOverview.kt @@ -16,13 +16,14 @@ package com.example.snippets.performance.baselineprofiles -import androidx.benchmark.macro.MacrobenchmarkScope import androidx.benchmark.macro.junit4.BaselineProfileRule import androidx.test.uiautomator.Direction +import androidx.test.uiautomator.textAsString +import androidx.test.uiautomator.uiAutomator import org.junit.Rule import org.junit.Test -private const val PACKAGE_NAME = "com.example.app" +private const val PACKAGE_NAME = "com.example.snippets" // [START android_performance_baselineprofiles_overview_generator] class BaselineProfileGenerator { @@ -48,23 +49,3 @@ class BaselineProfileGenerator { } } // [END android_performance_baselineprofiles_overview_generator] - -private class OverviewElementScope { - val viewIdResourceName: String = "" - fun textAsString(): String = "" -} - -private class OverviewElement { - fun click() {} - fun fling(direction: Direction) {} -} - -private class OverviewUiAutomatorScope { - fun startApp(packageName: String) {} - fun onElement(block: OverviewElementScope.() -> Boolean): OverviewElement = OverviewElement() - fun pressBack() {} -} - -private fun MacrobenchmarkScope.uiAutomator(block: OverviewUiAutomatorScope.() -> Unit) { - OverviewUiAutomatorScope().block() -} diff --git a/misc/src/main/java/com/example/snippets/performance/baselineprofiles/MeasureBaselineProfile.kt b/misc/src/androidTest/java/com/example/snippets/performance/baselineprofiles/MeasureBaselineProfile.kt similarity index 86% rename from misc/src/main/java/com/example/snippets/performance/baselineprofiles/MeasureBaselineProfile.kt rename to misc/src/androidTest/java/com/example/snippets/performance/baselineprofiles/MeasureBaselineProfile.kt index 696beb27f..2e25f9e12 100644 --- a/misc/src/main/java/com/example/snippets/performance/baselineprofiles/MeasureBaselineProfile.kt +++ b/misc/src/androidTest/java/com/example/snippets/performance/baselineprofiles/MeasureBaselineProfile.kt @@ -18,11 +18,11 @@ package com.example.snippets.performance.baselineprofiles import androidx.benchmark.macro.BaselineProfileMode import androidx.benchmark.macro.CompilationMode -import androidx.benchmark.macro.MacrobenchmarkScope import androidx.benchmark.macro.StartupMode import androidx.benchmark.macro.StartupTimingMetric import androidx.benchmark.macro.junit4.MacrobenchmarkRule import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner +import androidx.test.uiautomator.uiAutomator import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -78,18 +78,3 @@ class ColdStartupBenchmark { } } // [END android_performance_baselineprofiles_measure_compilation_modes] - -private class MeasureElementScope { - val viewIdResourceName: String = "" -} - -private class MeasureElement - -private class MeasureUiAutomatorScope { - fun startApp(packageName: String) {} - fun onElement(timeout: Long = 0L, block: MeasureElementScope.() -> Boolean): MeasureElement = MeasureElement() -} - -private fun MacrobenchmarkScope.uiAutomator(block: MeasureUiAutomatorScope.() -> Unit) { - MeasureUiAutomatorScope().block() -} diff --git a/misc/src/main/java/com/example/snippets/performance/benchmarking/MacrobenchmarkOverview.kt b/misc/src/androidTest/java/com/example/snippets/performance/benchmarking/MacrobenchmarkOverview.kt similarity index 100% rename from misc/src/main/java/com/example/snippets/performance/benchmarking/MacrobenchmarkOverview.kt rename to misc/src/androidTest/java/com/example/snippets/performance/benchmarking/MacrobenchmarkOverview.kt diff --git a/misc/src/main/java/com/example/snippets/performance/startupprofiles/DexLayoutOptimizations.kt b/misc/src/androidTest/java/com/example/snippets/performance/startupprofiles/DexLayoutOptimizations.kt similarity index 100% rename from misc/src/main/java/com/example/snippets/performance/startupprofiles/DexLayoutOptimizations.kt rename to misc/src/androidTest/java/com/example/snippets/performance/startupprofiles/DexLayoutOptimizations.kt diff --git a/misc/src/main/AndroidManifest.xml b/misc/src/main/AndroidManifest.xml index 839fe253f..4fb2f0024 100644 --- a/misc/src/main/AndroidManifest.xml +++ b/misc/src/main/AndroidManifest.xml @@ -71,10 +71,10 @@ android:authorities="com.example.snippets.androidx-startup" android:exported="false"> diff --git a/misc/src/main/java/com/example/snippets/ActivityEmbeddingJavaSnippets.java b/misc/src/main/java/com/example/snippets/ActivityEmbeddingJavaSnippets.java index a0ed0595b..4e9865cbe 100644 --- a/misc/src/main/java/com/example/snippets/ActivityEmbeddingJavaSnippets.java +++ b/misc/src/main/java/com/example/snippets/ActivityEmbeddingJavaSnippets.java @@ -264,7 +264,7 @@ void onOpenSubdetail() { /** @noinspection InnerClassMayBeStatic */ // [START android_activity_embedding_SplitInitializer_class_java] - public class SplitInitializer implements Initializer { + public static class SplitInitializer implements Initializer { @NonNull @Override From 715d37c94188cb7e770fb296756eda37c6ac1faa Mon Sep 17 00:00:00 2001 From: Peng Quah Date: Tue, 1 Sep 2026 14:46:56 -0400 Subject: [PATCH 03/11] Clean up testing dependencies - Consolidate and clean up testing dependencies in `misc/build.gradle.kts`. - Reorganize UI Automator library declaration in `libs.versions.toml` for better consistency. --- gradle/libs.versions.toml | 2 +- misc/build.gradle.kts | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 96af3d932..cf300d8a6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -270,13 +270,13 @@ androidx-test-core-ktx = { module = "androidx.test:core-ktx", version.ref = "and androidx-test-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "androidx-test-espresso" } androidx-test-ext-junit = { module = "androidx.test.ext:junit", version.ref = "androidx-test-junit" } androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidx-test" } -androidx-uiautomator = { module = "androidx.test.uiautomator:uiautomator", version.ref = "androidx-uiautomator" } androidx-tiles = { module = "androidx.wear.tiles:tiles", version.ref = "tiles" } androidx-tiles-renderer = { module = "androidx.wear.tiles:tiles-renderer", version.ref = "tiles" } androidx-tiles-testing = { module = "androidx.wear.tiles:tiles-testing", version.ref = "tiles" } androidx-tiles-tooling = { module = "androidx.wear.tiles:tiles-tooling", version.ref = "tiles" } androidx-tiles-tooling-preview = { module = "androidx.wear.tiles:tiles-tooling-preview", version.ref = "tiles" } androidx-tracing = { module = "androidx.tracing:tracing", version.ref = "tracing" } +androidx-uiautomator = { module = "androidx.test.uiautomator:uiautomator", version.ref = "androidx-uiautomator" } androidx-watchface-complications-data-source-ktx = { module = "androidx.wear.watchface:watchface-complications-data-source-ktx", version.ref = "watchfaceComplicationsDataSourceKtx" } androidx-watchfacepush = { module = "androidx.wear.watchfacepush:watchfacepush", version.ref = "wfp" } androidx-wear = { module = "androidx.wear:wear", version.ref = "wear" } diff --git a/misc/build.gradle.kts b/misc/build.gradle.kts index 0c299b619..f3a488a19 100644 --- a/misc/build.gradle.kts +++ b/misc/build.gradle.kts @@ -83,12 +83,6 @@ dependencies { implementation(libs.engage.core) implementation(libs.androidx.metrics.performance) - androidTestImplementation(libs.androidx.benchmark.macro.junit4) - androidTestImplementation(libs.androidx.uiautomator) - implementation(libs.junit) - implementation(libs.androidx.test.ext.junit) - implementation(libs.androidx.test.runner) - testImplementation(libs.junit) testImplementation(kotlin("test")) androidTestImplementation(libs.androidx.test.ext.junit) @@ -96,4 +90,6 @@ dependencies { androidTestImplementation(libs.androidx.test.core) androidTestImplementation(libs.androidx.test.runner) androidTestImplementation(libs.androidx.test.espresso.core) + androidTestImplementation(libs.androidx.benchmark.macro.junit4) + androidTestImplementation(libs.androidx.uiautomator) } From ad76a1c84343d8a93aad49ff5b824b2ba1e0083e Mon Sep 17 00:00:00 2001 From: Peng Quah Date: Mon, 14 Sep 2026 14:00:02 -0400 Subject: [PATCH 04/11] Move files to performance module --- misc/build.gradle.kts | 3 --- performance/build.gradle.kts | 5 +++++ .../performance/baselineprofiles/BaselineProfilesOverview.kt | 2 +- .../performance/baselineprofiles/MeasureBaselineProfile.kt | 2 +- .../performance/benchmarking/MacrobenchmarkOverview.kt | 2 +- .../performance/startupprofiles/DexLayoutOptimizations.kt | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) rename {misc/src/androidTest/java/com/example/snippets => performance/src/androidTest/java/com/example/android}/performance/baselineprofiles/BaselineProfilesOverview.kt (96%) rename {misc/src/androidTest/java/com/example/snippets => performance/src/androidTest/java/com/example/android}/performance/baselineprofiles/MeasureBaselineProfile.kt (98%) rename {misc/src/androidTest/java/com/example/snippets => performance/src/androidTest/java/com/example/android}/performance/benchmarking/MacrobenchmarkOverview.kt (97%) rename {misc/src/androidTest/java/com/example/snippets => performance/src/androidTest/java/com/example/android}/performance/startupprofiles/DexLayoutOptimizations.kt (97%) diff --git a/misc/build.gradle.kts b/misc/build.gradle.kts index f3a488a19..6b2374365 100644 --- a/misc/build.gradle.kts +++ b/misc/build.gradle.kts @@ -82,7 +82,6 @@ dependencies { implementation(libs.engage.core) - implementation(libs.androidx.metrics.performance) testImplementation(libs.junit) testImplementation(kotlin("test")) androidTestImplementation(libs.androidx.test.ext.junit) @@ -90,6 +89,4 @@ dependencies { androidTestImplementation(libs.androidx.test.core) androidTestImplementation(libs.androidx.test.runner) androidTestImplementation(libs.androidx.test.espresso.core) - androidTestImplementation(libs.androidx.benchmark.macro.junit4) - androidTestImplementation(libs.androidx.uiautomator) } diff --git a/performance/build.gradle.kts b/performance/build.gradle.kts index 64f15da1b..3390626ae 100644 --- a/performance/build.gradle.kts +++ b/performance/build.gradle.kts @@ -32,4 +32,9 @@ android { dependencies { implementation(libs.androidx.activity.compose) + implementation(libs.androidx.metrics.performance) + androidTestImplementation(libs.androidx.benchmark.macro.junit4) + androidTestImplementation(libs.androidx.uiautomator) + androidTestImplementation(libs.androidx.test.ext.junit) + androidTestImplementation(libs.androidx.test.runner) } \ No newline at end of file diff --git a/misc/src/androidTest/java/com/example/snippets/performance/baselineprofiles/BaselineProfilesOverview.kt b/performance/src/androidTest/java/com/example/android/performance/baselineprofiles/BaselineProfilesOverview.kt similarity index 96% rename from misc/src/androidTest/java/com/example/snippets/performance/baselineprofiles/BaselineProfilesOverview.kt rename to performance/src/androidTest/java/com/example/android/performance/baselineprofiles/BaselineProfilesOverview.kt index 283db7d6f..b713319e1 100644 --- a/misc/src/androidTest/java/com/example/snippets/performance/baselineprofiles/BaselineProfilesOverview.kt +++ b/performance/src/androidTest/java/com/example/android/performance/baselineprofiles/BaselineProfilesOverview.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.snippets.performance.baselineprofiles +package com.example.android.performance.baselineprofiles import androidx.benchmark.macro.junit4.BaselineProfileRule import androidx.test.uiautomator.Direction diff --git a/misc/src/androidTest/java/com/example/snippets/performance/baselineprofiles/MeasureBaselineProfile.kt b/performance/src/androidTest/java/com/example/android/performance/baselineprofiles/MeasureBaselineProfile.kt similarity index 98% rename from misc/src/androidTest/java/com/example/snippets/performance/baselineprofiles/MeasureBaselineProfile.kt rename to performance/src/androidTest/java/com/example/android/performance/baselineprofiles/MeasureBaselineProfile.kt index 2e25f9e12..17674946c 100644 --- a/misc/src/androidTest/java/com/example/snippets/performance/baselineprofiles/MeasureBaselineProfile.kt +++ b/performance/src/androidTest/java/com/example/android/performance/baselineprofiles/MeasureBaselineProfile.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.snippets.performance.baselineprofiles +package com.example.android.performance.baselineprofiles import androidx.benchmark.macro.BaselineProfileMode import androidx.benchmark.macro.CompilationMode diff --git a/misc/src/androidTest/java/com/example/snippets/performance/benchmarking/MacrobenchmarkOverview.kt b/performance/src/androidTest/java/com/example/android/performance/benchmarking/MacrobenchmarkOverview.kt similarity index 97% rename from misc/src/androidTest/java/com/example/snippets/performance/benchmarking/MacrobenchmarkOverview.kt rename to performance/src/androidTest/java/com/example/android/performance/benchmarking/MacrobenchmarkOverview.kt index 26e63cdf3..b032f15ad 100644 --- a/misc/src/androidTest/java/com/example/snippets/performance/benchmarking/MacrobenchmarkOverview.kt +++ b/performance/src/androidTest/java/com/example/android/performance/benchmarking/MacrobenchmarkOverview.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.snippets.performance.benchmarking +package com.example.android.performance.benchmarking import androidx.benchmark.macro.FrameTimingMetric import androidx.benchmark.macro.StartupMode diff --git a/misc/src/androidTest/java/com/example/snippets/performance/startupprofiles/DexLayoutOptimizations.kt b/performance/src/androidTest/java/com/example/android/performance/startupprofiles/DexLayoutOptimizations.kt similarity index 97% rename from misc/src/androidTest/java/com/example/snippets/performance/startupprofiles/DexLayoutOptimizations.kt rename to performance/src/androidTest/java/com/example/android/performance/startupprofiles/DexLayoutOptimizations.kt index e7a0b3256..412cceb5b 100644 --- a/misc/src/androidTest/java/com/example/snippets/performance/startupprofiles/DexLayoutOptimizations.kt +++ b/performance/src/androidTest/java/com/example/android/performance/startupprofiles/DexLayoutOptimizations.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.snippets.performance.startupprofiles +package com.example.android.performance.startupprofiles import android.content.Intent import androidx.benchmark.macro.MacrobenchmarkScope From c10dc2bc74bff5a34a287aa13e9fd2869493d073 Mon Sep 17 00:00:00 2001 From: Peng Quah Date: Mon, 14 Sep 2026 14:08:06 -0400 Subject: [PATCH 05/11] Upgrade androidx-metrics and fix SplitInitializer pathing - Remove static modifier from ActivityEmbeddingJavaSnippets.SplitInitializer - Fix AndroidManifest App Startup meta-data inner class reference paths - Update androidx-metrics to 1.0.0 --- gradle/libs.versions.toml | 2 +- misc/src/main/AndroidManifest.xml | 4 ++-- .../com/example/snippets/ActivityEmbeddingJavaSnippets.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index cf300d8a6..1a3f66a11 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -28,7 +28,7 @@ androidx-glance-appwidget = "1.3.0-alpha02" androidx-lifecycle-compose = "2.11.0" androidx-lifecycle-runtime-compose = "2.11.0" androidx-lifecycle-viewmodel-navigation3 = "2.11.0" -androidx-metrics = "1.0.0-beta01" +androidx-metrics = "1.0.0" androidx-navigation = "2.9.8" androidx-navigation3 = "1.2.0-beta01" androidx-paging = "3.5.0" diff --git a/misc/src/main/AndroidManifest.xml b/misc/src/main/AndroidManifest.xml index 4fb2f0024..839fe253f 100644 --- a/misc/src/main/AndroidManifest.xml +++ b/misc/src/main/AndroidManifest.xml @@ -71,10 +71,10 @@ android:authorities="com.example.snippets.androidx-startup" android:exported="false"> diff --git a/misc/src/main/java/com/example/snippets/ActivityEmbeddingJavaSnippets.java b/misc/src/main/java/com/example/snippets/ActivityEmbeddingJavaSnippets.java index 4e9865cbe..a0ed0595b 100644 --- a/misc/src/main/java/com/example/snippets/ActivityEmbeddingJavaSnippets.java +++ b/misc/src/main/java/com/example/snippets/ActivityEmbeddingJavaSnippets.java @@ -264,7 +264,7 @@ void onOpenSubdetail() { /** @noinspection InnerClassMayBeStatic */ // [START android_activity_embedding_SplitInitializer_class_java] - public static class SplitInitializer implements Initializer { + public class SplitInitializer implements Initializer { @NonNull @Override From 036dba93a0a8cf36ba38888ca2ba72c55ec7dc94 Mon Sep 17 00:00:00 2001 From: Peng Quah Date: Tue, 15 Sep 2026 16:16:57 -0400 Subject: [PATCH 06/11] Remove unused mock helper class --- .../startupprofiles/DexLayoutOptimizations.kt | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/performance/src/androidTest/java/com/example/android/performance/startupprofiles/DexLayoutOptimizations.kt b/performance/src/androidTest/java/com/example/android/performance/startupprofiles/DexLayoutOptimizations.kt index 412cceb5b..740ad3003 100644 --- a/performance/src/androidTest/java/com/example/android/performance/startupprofiles/DexLayoutOptimizations.kt +++ b/performance/src/androidTest/java/com/example/android/performance/startupprofiles/DexLayoutOptimizations.kt @@ -17,10 +17,10 @@ package com.example.android.performance.startupprofiles import android.content.Intent -import androidx.benchmark.macro.MacrobenchmarkScope import androidx.benchmark.macro.junit4.BaselineProfileRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest +import androidx.test.uiautomator.uiAutomator import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -52,11 +52,3 @@ class BaselineProfileGenerator { } } // [END android_performance_startupprofiles_generator] - -private class UiAutomatorScope(val packageName: String) { - fun startIntent(intent: Intent) {} -} - -private fun MacrobenchmarkScope.uiAutomator(block: UiAutomatorScope.() -> Unit) { - UiAutomatorScope(packageName).block() -} From 8c450f3ffc8739be871daaa5cf219d084c1dd7e5 Mon Sep 17 00:00:00 2001 From: Peng Quah Date: Wed, 16 Sep 2026 15:45:09 -0400 Subject: [PATCH 07/11] Move classes from misc module to performance --- .../snippets/performance/vitals/LaunchTime.kt | 82 ------------------- .../performance/jankstats/JankStats.kt | 2 +- 2 files changed, 1 insertion(+), 83 deletions(-) delete mode 100644 misc/src/main/java/com/example/snippets/performance/vitals/LaunchTime.kt rename {misc/src/main/java/com/example/snippets => performance/src/main/java/com/example/android}/performance/jankstats/JankStats.kt (96%) diff --git a/misc/src/main/java/com/example/snippets/performance/vitals/LaunchTime.kt b/misc/src/main/java/com/example/snippets/performance/vitals/LaunchTime.kt deleted file mode 100644 index 752c0fdfa..000000000 --- a/misc/src/main/java/com/example/snippets/performance/vitals/LaunchTime.kt +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2026 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.example.snippets.performance.vitals - -import android.os.Bundle -import androidx.activity.ComponentActivity -import androidx.activity.compose.setContent -import androidx.compose.runtime.Composable -import androidx.compose.runtime.SideEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.lifecycle.lifecycleScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch - -private object LaunchTimeSnippet { - // [START android_performance_launch_time_fully_drawn_reporter] - class MainActivity : ComponentActivity() { - - sealed interface ActivityState { - data object LOADING : ActivityState - data object LOADED : ActivityState - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - setContent { - var activityState by remember { - mutableStateOf(ActivityState.LOADING as ActivityState) - } - fullyDrawnReporter.addOnReportDrawnListener { - activityState = ActivityState.LOADED - } - ReportFullyDrawnTheme { - when(activityState) { - is ActivityState.LOADING -> { - // Display the loading UI. - } - is ActivityState.LOADED -> { - // Display the full UI. - } - } - } - SideEffect { - fullyDrawnReporter.addReporter() - lifecycleScope.launch(Dispatchers.IO) { - // Perform the background operation. - fullyDrawnReporter.removeReporter() - } - fullyDrawnReporter.addReporter() - lifecycleScope.launch(Dispatchers.IO) { - // Perform the background operation. - fullyDrawnReporter.removeReporter() - } - } - } - } - } - // [END android_performance_launch_time_fully_drawn_reporter] -} - -@Composable -private fun ReportFullyDrawnTheme(content: @Composable () -> Unit) { - content() -} diff --git a/misc/src/main/java/com/example/snippets/performance/jankstats/JankStats.kt b/performance/src/main/java/com/example/android/performance/jankstats/JankStats.kt similarity index 96% rename from misc/src/main/java/com/example/snippets/performance/jankstats/JankStats.kt rename to performance/src/main/java/com/example/android/performance/jankstats/JankStats.kt index c3b718d32..aaf106b2e 100644 --- a/misc/src/main/java/com/example/snippets/performance/jankstats/JankStats.kt +++ b/performance/src/main/java/com/example/android/performance/jankstats/JankStats.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.snippets.performance.jankstats +package com.example.android.performance.jankstats import android.view.View import androidx.activity.ComponentActivity From 4fc02939310d65e85979a013e24b31ef858aefb0 Mon Sep 17 00:00:00 2001 From: Peng Quah Date: Thu, 17 Sep 2026 09:17:27 -0400 Subject: [PATCH 08/11] Add new line --- performance/build.gradle.kts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/performance/build.gradle.kts b/performance/build.gradle.kts index 3390626ae..715832425 100644 --- a/performance/build.gradle.kts +++ b/performance/build.gradle.kts @@ -37,4 +37,5 @@ dependencies { androidTestImplementation(libs.androidx.uiautomator) androidTestImplementation(libs.androidx.test.ext.junit) androidTestImplementation(libs.androidx.test.runner) -} \ No newline at end of file +} + From 163d29f26e42fb6bc94c1bb1c99f133f8e882743 Mon Sep 17 00:00:00 2001 From: Peng Quah Date: Mon, 21 Sep 2026 16:18:42 +0000 Subject: [PATCH 09/11] Remove snippets that are not required atm and reorganize test dependencies --- performance/build.gradle.kts | 2 +- .../benchmarking/MacrobenchmarkOverview.kt | 55 ------------------- .../performance/jankstats/JankStats.kt | 35 ------------ 3 files changed, 1 insertion(+), 91 deletions(-) delete mode 100644 performance/src/androidTest/java/com/example/android/performance/benchmarking/MacrobenchmarkOverview.kt delete mode 100644 performance/src/main/java/com/example/android/performance/jankstats/JankStats.kt diff --git a/performance/build.gradle.kts b/performance/build.gradle.kts index 715832425..4247e781e 100644 --- a/performance/build.gradle.kts +++ b/performance/build.gradle.kts @@ -34,8 +34,8 @@ dependencies { implementation(libs.androidx.activity.compose) implementation(libs.androidx.metrics.performance) androidTestImplementation(libs.androidx.benchmark.macro.junit4) - androidTestImplementation(libs.androidx.uiautomator) androidTestImplementation(libs.androidx.test.ext.junit) androidTestImplementation(libs.androidx.test.runner) + androidTestImplementation(libs.androidx.uiautomator) } diff --git a/performance/src/androidTest/java/com/example/android/performance/benchmarking/MacrobenchmarkOverview.kt b/performance/src/androidTest/java/com/example/android/performance/benchmarking/MacrobenchmarkOverview.kt deleted file mode 100644 index b032f15ad..000000000 --- a/performance/src/androidTest/java/com/example/android/performance/benchmarking/MacrobenchmarkOverview.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2026 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.example.android.performance.benchmarking - -import androidx.benchmark.macro.FrameTimingMetric -import androidx.benchmark.macro.StartupMode -import androidx.benchmark.macro.junit4.MacrobenchmarkRule -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.filters.LargeTest -import androidx.test.uiautomator.By -import androidx.test.uiautomator.Direction -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith - -// [START android_performance_macrobenchmark_compose_scroll] -@LargeTest -@RunWith(AndroidJUnit4::class) -class ComposeScrollBenchmark { - @get:Rule - val benchmarkRule = MacrobenchmarkRule() - - @Test - fun scrollLazyColumn() = benchmarkRule.measureRepeated( - packageName = "com.example.compose.app", - metrics = listOf(FrameTimingMetric()), - iterations = 5, - startupMode = StartupMode.WARM, - setupBlock = { pressHome() } - ) { - startActivityAndWait() - - // Find the Compose node using the testTag defined in your app - val lazyColumn = device.findObject(By.res("my_lazy_column")) - - // Simulate a scroll gesture to measure FrameTimingMetric - lazyColumn.setGestureMargin(device.displayWidth / 5) - lazyColumn.fling(Direction.DOWN) - } -} -// [END android_performance_macrobenchmark_compose_scroll] diff --git a/performance/src/main/java/com/example/android/performance/jankstats/JankStats.kt b/performance/src/main/java/com/example/android/performance/jankstats/JankStats.kt deleted file mode 100644 index aaf106b2e..000000000 --- a/performance/src/main/java/com/example/android/performance/jankstats/JankStats.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2026 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.example.android.performance.jankstats - -import android.view.View -import androidx.activity.ComponentActivity -import androidx.metrics.performance.PerformanceMetricsState - -private class JankStatsActivity : ComponentActivity() { - private lateinit var binding: MyBinding - - private class MyBinding(val root: View) - - private fun setupJankStats() { - // [START android_performance_jankstats_state_holder] - val metricsStateHolder = PerformanceMetricsState.getHolderForHierarchy(binding.root) - // ... - metricsStateHolder.state?.putState("Activity", javaClass.simpleName) - // [END android_performance_jankstats_state_holder] - } -} From b3640eadc526c98eee236fece06db75d877605f1 Mon Sep 17 00:00:00 2001 From: Peng Quah Date: Mon, 21 Sep 2026 16:42:10 +0000 Subject: [PATCH 10/11] Replace internal class for JUnit with public --- .../performance/baselineprofiles/MeasureBaselineProfile.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/performance/src/androidTest/java/com/example/android/performance/baselineprofiles/MeasureBaselineProfile.kt b/performance/src/androidTest/java/com/example/android/performance/baselineprofiles/MeasureBaselineProfile.kt index 17674946c..e16c87f43 100644 --- a/performance/src/androidTest/java/com/example/android/performance/baselineprofiles/MeasureBaselineProfile.kt +++ b/performance/src/androidTest/java/com/example/android/performance/baselineprofiles/MeasureBaselineProfile.kt @@ -21,14 +21,14 @@ import androidx.benchmark.macro.CompilationMode import androidx.benchmark.macro.StartupMode import androidx.benchmark.macro.StartupTimingMetric import androidx.benchmark.macro.junit4.MacrobenchmarkRule -import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner +import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.uiautomator.uiAutomator import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith // [START android_performance_baselineprofiles_measure_compilation_modes] -@RunWith(AndroidJUnit4ClassRunner::class) +@RunWith(AndroidJUnit4::class) class ColdStartupBenchmark { @get:Rule val benchmarkRule = MacrobenchmarkRule() From 33457fd01a0118dc14f861bd4d375b03a13919e4 Mon Sep 17 00:00:00 2001 From: Peng Quah Date: Wed, 7 Oct 2026 13:19:30 +0000 Subject: [PATCH 11/11] Remove unused androidx-metrics-performance dependency --- gradle/libs.versions.toml | 2 -- performance/build.gradle.kts | 1 - 2 files changed, 3 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1a3f66a11..e84276322 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -28,7 +28,6 @@ androidx-glance-appwidget = "1.3.0-alpha02" androidx-lifecycle-compose = "2.11.0" androidx-lifecycle-runtime-compose = "2.11.0" androidx-lifecycle-viewmodel-navigation3 = "2.11.0" -androidx-metrics = "1.0.0" androidx-navigation = "2.9.8" androidx-navigation3 = "1.2.0-beta01" androidx-paging = "3.5.0" @@ -235,7 +234,6 @@ androidx-media3-session = { module = "androidx.media3:media3-session", version.r androidx-media3-ui = { module = "androidx.media3:media3-ui", version.ref = "media3Ui" } androidx-media3-ui-compose = { module = "androidx.media3:media3-ui-compose", version.ref = "media3Ui" } androidx-media3-ui-compose-material3 = { module = "androidx.media3:media3-ui-compose-material3", version.ref = "media3Ui" } -androidx-metrics-performance = { module = "androidx.metrics:metrics-performance", version.ref = "androidx-metrics" } androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "androidx-navigation" } androidx-navigation3-runtime = { module = "androidx.navigation3:navigation3-runtime", version.ref = "androidx-navigation3" } androidx-navigation3-ui = { module = "androidx.navigation3:navigation3-ui", version.ref = "androidx-navigation3" } diff --git a/performance/build.gradle.kts b/performance/build.gradle.kts index 4247e781e..2bd7d9b21 100644 --- a/performance/build.gradle.kts +++ b/performance/build.gradle.kts @@ -32,7 +32,6 @@ android { dependencies { implementation(libs.androidx.activity.compose) - implementation(libs.androidx.metrics.performance) androidTestImplementation(libs.androidx.benchmark.macro.junit4) androidTestImplementation(libs.androidx.test.ext.junit) androidTestImplementation(libs.androidx.test.runner)