-
Notifications
You must be signed in to change notification settings - Fork 141
Drive by cleanup #149
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
base: main
Are you sure you want to change the base?
Drive by cleanup #149
Changes from all commits
fdc246c
e4d8529
055d035
3ee7821
f749476
9644c33
e9982d6
bd0611f
15a9cc4
992fd5f
4fe2c46
abb1ac9
b0f5c1b
4463f8f
36e7a05
08e7560
42a27e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Benchmarks | ||
|
|
||
| This module contains [Macrobenchmarks](https://developer.android.com/topic/performance/benchmarking/macrobenchmark-overview) for the application. | ||
|
|
||
| ## What are Macrobenchmarks? | ||
|
|
||
| Macrobenchmarks allow you to measure the performance of your application in a realistic environment. | ||
| In this sample we rely on test for: | ||
| * **Startup:** Measuring the time it takes for the app to launch. | ||
| * **Frame Timing:** Measuring the jank and dropped frames during animations. | ||
|
|
||
| Macrobenchmarks run the app as a user would, interacting with the system and other apps. | ||
|
|
||
| ## How to Run Benchmarks | ||
|
|
||
| To run the benchmarks, you can use the Gradle task or run them directly from Android Studio. | ||
|
|
||
| ### Using Gradle | ||
|
|
||
| Run the following command in the terminal from the project root: | ||
|
|
||
| ```bash | ||
| ./gradlew :benchmark:connectedCheck | ||
| ``` | ||
|
|
||
| ### Using Android Studio | ||
|
|
||
| 1. Open the `benchmark` module in the project view. | ||
| 2. Navigate to the benchmark class you want to run (usually in `src/main/kotlin`). | ||
| 3. Click the green run icon next to the class or test method. | ||
| 4. Select "Run '...'" to execute the benchmark on a connected device. | ||
|
|
||
| **Note:** For accurate results, run benchmarks on a physical device. Emulators will not provide | ||
| consistent performance metrics. | ||
|
|
||
| ## Documentation | ||
|
|
||
| For more information on writing and running Macrobenchmarks, refer to the official documentation: | ||
| * [Macrobenchmark Overview](https://developer.android.com/topic/performance/benchmarking/macrobenchmark-overview) | ||
| * [Write a Macrobenchmark](https://developer.android.com/topic/performance/benchmarking/macrobenchmark-write) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
|
|
||
| /* | ||
| * 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. | ||
| */ | ||
| plugins { | ||
| alias(libs.plugins.android.test) | ||
| alias(libs.plugins.jetbrains.kotlin.android) | ||
| } | ||
|
|
||
| android { | ||
| namespace = "com.android.ai.catalog.benchmark" | ||
| compileSdk { | ||
| version = release(36) | ||
| } | ||
|
|
||
| defaultConfig { | ||
| minSdk = 24 | ||
| targetSdk = 36 | ||
|
|
||
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
| } | ||
|
|
||
| buildTypes { | ||
| // This benchmark buildType is used for benchmarking, and should function like your | ||
| // release build (for example, with minification on). It"s signed with a debug key | ||
| // for easy local/CI testing. | ||
| create("benchmark") { | ||
| isDebuggable = true | ||
| signingConfig = getByName("debug").signingConfig | ||
| matchingFallbacks += listOf("release") | ||
| } | ||
| } | ||
|
|
||
| targetProjectPath = ":app" | ||
| experimentalProperties["android.experimental.self-instrumenting"] = true | ||
|
|
||
| compileOptions { | ||
| sourceCompatibility = JavaVersion.VERSION_17 | ||
| targetCompatibility = JavaVersion.VERSION_17 | ||
| } | ||
| kotlin { | ||
| compilerOptions { jvmTarget.set(JvmTarget.JVM_17) } | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(libs.androidx.junit) | ||
| implementation(libs.androidx.espresso.core) | ||
| implementation(libs.androidx.uiautomator) | ||
| implementation(libs.androidx.benchmark.macro.junit4) | ||
| } | ||
|
|
||
| androidComponents { | ||
| beforeVariants(selector().all()) { | ||
| it.enable = it.buildType == "benchmark" | ||
| } | ||
| } |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove this, if we don't need it.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even without manual content the |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <manifest /> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * 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.android.ai.catalog.benchmark | ||
|
|
||
| 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 | ||
|
|
||
| /** | ||
| * Benchmark class to measure the startup timing of the application. | ||
| * | ||
| * This benchmark uses [MacrobenchmarkRule] to measure the time it takes for the application | ||
| * to start up in [StartupMode.COLD] mode. | ||
| */ | ||
| @RunWith(AndroidJUnit4::class) | ||
| class StartupBenchmark { | ||
| @get:Rule | ||
| val benchmarkRule = MacrobenchmarkRule() | ||
|
|
||
| /** | ||
| * Measures the application startup time. | ||
| * | ||
| * It runs the benchmark for 5 iterations using [StartupTimingMetric]. | ||
| * The application is started in [StartupMode.COLD] mode, ensuring a fresh start for each iteration. | ||
| */ | ||
| @Test | ||
| fun startup() = benchmarkRule.measureRepeated( | ||
| packageName = "com.android.ai.catalog", | ||
| metrics = listOf(StartupTimingMetric()), | ||
| iterations = 5, | ||
| startupMode = StartupMode.COLD, | ||
| ) { | ||
| startApp(packageName) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am curious why this import re-ordering isn't something that Detekt in the github action picked up. Did you run manually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a pre-push or even pre-commit hook. For now its manual.