<NME> TrivialBaselineProfileBenchmark.kt
<BEF> /*
 * Copyright 2022 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
 *
 *      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.example.macrobenchmark

import androidx.benchmark.macro.ExperimentalBaselineProfilesApi
import androidx.benchmark.macro.junit4.BaselineProfileRule
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test

@OptIn(ExperimentalBaselineProfilesApi::class)
// Remove @Ignore to actually run the test using a rooted device/emulator.
// Generally emulator images without Google Play Services are user-debug builds, which support
// `adb root`

// For the output baseline profile file, look at the `Benchmark` tag in logcat for the location
// of the output directory.
//@Ignore
/**
 * This benchmark generates a basic baseline profile for the target package.
 * Refer to the [baseline profile documentation](https://developer.android.com/studio/profile/baselineprofiles)
 * for more information.
 */
class TrivialBaselineProfileBenchmark {
    // [START baseline_profile_basic]
    @get:Rule
class TrivialBaselineProfileBenchmark {
    // [START baseline_profile_basic]
    @get:Rule
    val baselineProfileRule = BaselineProfileRule()

    @Test
    fun appStartupOnly() = baselineProfileRule.collectBaselineProfile(
        packageName = TARGET_PACKAGE,
        profileBlock = {
            startActivityAndWait()
        }
    )
    // [END baseline_profile_basic]

    /**
     * A more real world baseline profile collection method.
     * The collection starts at app startup and then goes through several user journeys.
     * This enables ahead of time compilation for these paths, making them smoother for users
     * from the first start.
     */
    @Test
    fun appStartupAndUserJourneys() =
        baselineProfileRule.collectBaselineProfile(packageName = TARGET_PACKAGE, profileBlock = {
            startActivityAndWait()
            with(device) {
                findObject(By.text("RECYCLERVIEW")).clickAndWait(Until.newWindow(), 500L)
                with(
                    findObject(
                        By.res("com.example.macrobenchmark.target", "recycler")
                    )
                ) {
                    fling(Direction.DOWN)
                    waitForIdle()
                    fling(Direction.UP)
                    pressBack()
                }

                findObject(By.text("COMPOSE LAZYLIST")).clickAndWait(Until.newWindow(), 500L)
                with(findObject(By.res("myLazyColumn"))) {
                    fling(Direction.DOWN)
                    waitForIdle()
                    fling(Direction.UP)
                    pressBack()
                }
            }
        })

}

<MSG> Merge pull request #159 from android/tm/filter-ftl-benchmarks

Fix FTL tests to run only Macrobenchmarks
<DFF> @@ -18,23 +18,27 @@ package com.example.macrobenchmark
 
 import androidx.benchmark.macro.ExperimentalBaselineProfilesApi
 import androidx.benchmark.macro.junit4.BaselineProfileRule
-import org.junit.Ignore
 import org.junit.Rule
 import org.junit.Test
 
-@OptIn(ExperimentalBaselineProfilesApi::class)
-// Remove @Ignore to actually run the test using a rooted device/emulator.
-// Generally emulator images without Google Play Services are user-debug builds, which support
-// `adb root`
-
-// For the output baseline profile file, look at the `Benchmark` tag in logcat for the location
-// of the output directory.
-//@Ignore
 /**
  * This benchmark generates a basic baseline profile for the target package.
- * Refer to the [baseline profile documentation](https://developer.android.com/studio/profile/baselineprofiles)
+ * Refer to the [baseline profile documentation](https://developer.android.com/topic/performance/baselineprofiles)
  * for more information.
+ *
+ * You need to run the test on a rooted device/emulator. Generally emulator images without
+ * Google Play Services are user-debug builds and support `adb root`.
+ *
+ * For the output Baseline Profile file, look at the folder
+ * `macrobenchmark/build/outputs/connected_android_test_additional_output/benchmark/[device name]/`,
+ * which contains the file [name-of-test]-baseline.prof.txt and copy the file into src/main/
+ * (next to AndroidManifest.xml) and rename it to baseline-prof.txt.
+ *
+ * To filter out the generator when running benchmarks on CI, use instrumentation argument:
+ * androidx.benchmark.enabledRules=Macrobenchmark
+ * (see [documentation](https://android.devsite.corp.google.com/topic/performance/benchmarking/macrobenchmark-instrumentation-args) for more info)
  */
+@OptIn(ExperimentalBaselineProfilesApi::class)
 class TrivialBaselineProfileBenchmark {
     // [START baseline_profile_basic]
     @get:Rule

{'commit': 'diff --git a/.github/workflows/firebase_test_lab.yml b/.github/workflows/firebase_test_lab.yml\nindex a0042c5..38449a8 100644\n--- a/.github/workflows/firebase_test_lab.yml\n+++ b/.github/workflows/firebase_test_lab.yml\n@@ -51,7 +51,9 @@ jobs:\n         env:\n           JAVA_HOME: ${{ steps.setup-java.outputs.path }}\n         with:\n-          arguments: build\n+          arguments: |\n+            :app:assembleBenchmark\n+            :macrobenchmark:assembleBenchmark\n           build-root-directory: ${{ github.workspace }}/MacrobenchmarkSample\n           gradle-executable: ${{ github.workspace }}/MacrobenchmarkSample/gradlew\n           wrapper-directory: ${{ github.workspace }}/MacrobenchmarkSample/gradle/wrapper\n@@ -64,14 +66,18 @@ jobs:\n       - name: Set up Cloud SDK\n         uses: google-github-actions/setup-gcloud@v0\n       \n+      - name: Install Cloud SDK Beta components\n+        run: gcloud components install beta\n+      \n       - name: Run Macro Benchmarks\n         run: |\n-          gcloud firebase test android run \\\n+          gcloud beta firebase test android run \\\n             --type instrumentation \\\n             --app ${{ github.workspace }}/MacrobenchmarkSample/app/build/outputs/apk/benchmark/app-benchmark.apk \\\n             --test ${{ github.workspace }}/MacrobenchmarkSample/macrobenchmark/build/outputs/apk/benchmark/macrobenchmark-benchmark.apk \\\n             --device model=redfin,version=30,locale=en,orientation=portrait \\\n             --directories-to-pull /sdcard/Download \\\n             --results-bucket gs://macrobenchmark-results \\\n-            --environment-variables clearPackageData=true,additionalTestOutputDir=/sdcard/Download,no-isolated-storage=true \\\n+            --environment-variables clearPackageData=true,additionalTestOutputDir=/sdcard/Download,no-isolated-storage=true,androidx.benchmark.enabledRules=Macrobenchmark \\\n+            --num-uniform-shards 3 \\\n             --timeout 30m\ndiff --git a/MacrobenchmarkSample/ftl/README.md b/MacrobenchmarkSample/ftl/README.md\nindex e3ca5f0..205aece 100644\n--- a/MacrobenchmarkSample/ftl/README.md\n+++ b/MacrobenchmarkSample/ftl/README.md\n@@ -99,8 +99,8 @@ jobs:\n         run: |\n           gcloud firebase test android run \\\n             --type instrumentation \\\n-            --app ${{ github.workspace }}/.../benchmark/app-benchmark.apk \\\n-            --test ${{ github.workspace }}/.../macrobenchmark-benchmark.apk \\\n+            --app ${{ github.workspace }}/MacrobenchmarkSample/app/build/outputs/apk/benchmark/app-benchmark.apk \\\n+            --test ${{ github.workspace }}/MacrobenchmarkSample/macrobenchmark/build/outputs/apk/benchmark/macrobenchmark-benchmark.apk \\\n             --device model=redfin,version=30,locale=en,orientation=portrait \\\n             --directories-to-pull /sdcard/Download \\\n             --results-bucket gs://macrobenchmark-results \\\ndiff --git a/MacrobenchmarkSample/macrobenchmark/src/main/java/com/example/macrobenchmark/TrivialBaselineProfileBenchmark.kt b/MacrobenchmarkSample/macrobenchmark/src/main/java/com/example/macrobenchmark/TrivialBaselineProfileBenchmark.kt\nindex cd8d5aa..5109db0 100644\n--- a/MacrobenchmarkSample/macrobenchmark/src/main/java/com/example/macrobenchmark/TrivialBaselineProfileBenchmark.kt\n+++ b/MacrobenchmarkSample/macrobenchmark/src/main/java/com/example/macrobenchmark/TrivialBaselineProfileBenchmark.kt\n@@ -18,23 +18,27 @@ package com.example.macrobenchmark\n \n import androidx.benchmark.macro.ExperimentalBaselineProfilesApi\n import androidx.benchmark.macro.junit4.BaselineProfileRule\n-import org.junit.Ignore\n import org.junit.Rule\n import org.junit.Test\n \n-@OptIn(ExperimentalBaselineProfilesApi::class)\n-// Remove @Ignore to actually run the test using a rooted device/emulator.\n-// Generally emulator images without Google Play Services are user-debug builds, which support\n-// `adb root`\n-\n-// For the output baseline profile file, look at the `Benchmark` tag in logcat for the location\n-// of the output directory.\n-//@Ignore\n /**\n  * This benchmark generates a basic baseline profile for the target package.\n- * Refer to the [baseline profile documentation](https://developer.android.com/studio/profile/baselineprofiles)\n+ * Refer to the [baseline profile documentation](https://developer.android.com/topic/performance/baselineprofiles)\n  * for more information.\n+ *\n+ * You need to run the test on a rooted device/emulator. Generally emulator images without\n+ * Google Play Services are user-debug builds and support `adb root`.\n+ *\n+ * For the output Baseline Profile file, look at the folder\n+ * `macrobenchmark/build/outputs/connected_android_test_additional_output/benchmark/[device name]/`,\n+ * which contains the file [name-of-test]-baseline.prof.txt and copy the file into src/main/\n+ * (next to AndroidManifest.xml) and rename it to baseline-prof.txt.\n+ *\n+ * To filter out the generator when running benchmarks on CI, use instrumentation argument:\n+ * androidx.benchmark.enabledRules=Macrobenchmark\n+ * (see [documentation](https://android.devsite.corp.google.com/topic/performance/benchmarking/macrobenchmark-instrumentation-args) for more info)\n  */\n+@OptIn(ExperimentalBaselineProfilesApi::class)\n class TrivialBaselineProfileBenchmark {\n     // [START baseline_profile_basic]\n     @get:Rule\n', 'commit_subject': 'Merge pull request #159 from android/tm/filter-ftl-benchmarks', 'repo_name': 'android/performance-samples', 'committer': {'name': 'GitHub', 'email': '1505422b2465e9a84f6fdfaa161078890c593f06@github.com', 'time_sec': '1652889699', 'tz_offset': '0', 'date': {'seconds': '1652889699'}}, 'commit_tree': '3e97a2235b26020cfe1768f21a073bc68a2a4cb0', 'commit_message': 'Merge pull request #159 from android/tm/filter-ftl-benchmarks\n\nFix FTL tests to run only Macrobenchmarks', 'language_name': 'Shell', 'license': 'apache-2.0', 'hunks': '@@ -18,23 +18,27 @@ package com.example.macrobenchmark\n \n import androidx.benchmark.macro.ExperimentalBaselineProfilesApi\n import androidx.benchmark.macro.junit4.BaselineProfileRule\n-import org.junit.Ignore\n import org.junit.Rule\n import org.junit.Test\n \n-@OptIn(ExperimentalBaselineProfilesApi::class)\n-// Remove @Ignore to actually run the test using a rooted device/emulator.\n-// Generally emulator images without Google Play Services are user-debug builds, which support\n-// `adb root`\n-\n-// For the output baseline profile file, look at the `Benchmark` tag in logcat for the location\n-// of the output directory.\n-//@Ignore\n /**\n  * This benchmark generates a basic baseline profile for the target package.\n- * Refer to the [baseline profile documentation](https://developer.android.com/studio/profile/baselineprofiles)\n+ * Refer to the [baseline profile documentation](https://developer.android.com/topic/performance/baselineprofiles)\n  * for more information.\n+ *\n+ * You need to run the test on a rooted device/emulator. Generally emulator images without\n+ * Google Play Services are user-debug builds and support `adb root`.\n+ *\n+ * For the output Baseline Profile file, look at the folder\n+ * `macrobenchmark/build/outputs/connected_android_test_additional_output/benchmark/[device name]/`,\n+ * which contains the file [name-of-test]-baseline.prof.txt and copy the file into src/main/\n+ * (next to AndroidManifest.xml) and rename it to baseline-prof.txt.\n+ *\n+ * To filter out the generator when running benchmarks on CI, use instrumentation argument:\n+ * androidx.benchmark.enabledRules=Macrobenchmark\n+ * (see [documentation](https://android.devsite.corp.google.com/topic/performance/benchmarking/macrobenchmark-instrumentation-args) for more info)\n  */\n+@OptIn(ExperimentalBaselineProfilesApi::class)\n class TrivialBaselineProfileBenchmark {\n     // [START baseline_profile_basic]\n     @get:Rule\n', 'addition_count': 14, 'deletion_count': 10, 'src_file': 'a/MacrobenchmarkSample/macrobenchmark/src/main/java/com/example/macrobenchmark/TrivialBaselineProfileBenchmark.kt', 'tgt_file': 'b/MacrobenchmarkSample/macrobenchmark/src/main/java/com/example/macrobenchmark/TrivialBaselineProfileBenchmark.kt', 'file_extension': '.kt', 'before_file': '/*\n * Copyright 2022 The Android Open Source Project\n *\n * Licensed under the Apache License, Version 2.0 (the "License");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an "AS IS" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.example.macrobenchmark\n\nimport androidx.benchmark.macro.ExperimentalBaselineProfilesApi\nimport androidx.benchmark.macro.junit4.BaselineProfileRule\nimport org.junit.Ignore\nimport org.junit.Rule\nimport org.junit.Test\n\n@OptIn(ExperimentalBaselineProfilesApi::class)\n// Remove @Ignore to actually run the test using a rooted device/emulator.\n// Generally emulator images without Google Play Services are user-debug builds, which support\n// `adb root`\n\n// For the output baseline profile file, look at the `Benchmark` tag in logcat for the location\n// of the output directory.\n//@Ignore\n/**\n * This benchmark generates a basic baseline profile for the target package.\n * Refer to the [baseline profile documentation](https://developer.android.com/studio/profile/baselineprofiles)\n * for more information.\n */\nclass TrivialBaselineProfileBenchmark {\n    // [START baseline_profile_basic]\n    @get:Rule\nclass TrivialBaselineProfileBenchmark {\n    // [START baseline_profile_basic]\n    @get:Rule\n    val baselineProfileRule = BaselineProfileRule()\n\n    @Test\n    fun appStartupOnly() = baselineProfileRule.collectBaselineProfile(\n        packageName = TARGET_PACKAGE,\n        profileBlock = {\n            startActivityAndWait()\n        }\n    )\n    // [END baseline_profile_basic]\n\n    /**\n     * A more real world baseline profile collection method.\n     * The collection starts at app startup and then goes through several user journeys.\n     * This enables ahead of time compilation for these paths, making them smoother for users\n     * from the first start.\n     */\n    @Test\n    fun appStartupAndUserJourneys() =\n        baselineProfileRule.collectBaselineProfile(packageName = TARGET_PACKAGE, profileBlock = {\n            startActivityAndWait()\n            with(device) {\n                findObject(By.text("RECYCLERVIEW")).clickAndWait(Until.newWindow(), 500L)\n                with(\n                    findObject(\n                        By.res("com.example.macrobenchmark.target", "recycler")\n                    )\n                ) {\n                    fling(Direction.DOWN)\n                    waitForIdle()\n                    fling(Direction.UP)\n                    pressBack()\n                }\n\n                findObject(By.text("COMPOSE LAZYLIST")).clickAndWait(Until.newWindow(), 500L)\n                with(findObject(By.res("myLazyColumn"))) {\n                    fling(Direction.DOWN)\n                    waitForIdle()\n                    fling(Direction.UP)\n                    pressBack()\n                }\n            }\n        })\n\n}\n', 'message': 'Merge pull request #159 from android/tm/filter-ftl-benchmarks\n\nFix FTL tests to run only Macrobenchmarks', 'author_name': 'GitHub', 'lang': 'kt'}