Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5fb672e8 authored by Peter Kalauskas's avatar Peter Kalauskas
Browse files

Performance tests for structured concurrency

New microbenchmark tests for assessing performance of various styles of
structured concurrency for managing mutable state.

Test: atest StructuredConcurrencyPerfTests
Bug: 404377320
Flag: EXEMPT test
Change-Id: I7850148113411c5ef38d2b80dcfefcb32338a09d
parent de353672
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ clang_format = --commit ${PREUPLOAD_COMMIT} --style file --extensions c,h,cc,cpp
               tests/
               tools/
bpfmt = -d
ktfmt = --kotlinlang-style --include-dirs=services/permission,packages/SystemUI,libs/WindowManager/Shell/src/com/android/wm/shell/freeform,libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode,libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode,apct-tests,tests/Input
ktfmt = --kotlinlang-style --include-dirs=services/permission,packages/SystemUI,libs/WindowManager/Shell/src/com/android/wm/shell/freeform,libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode,libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode,apct-tests,tests/Input,tests/StructuredConcurrencyPerfTests

[Hook Scripts]
checkstyle_hook = ${REPO_ROOT}/prebuilts/checkstyle/checkstyle.py --sha ${PREUPLOAD_COMMIT}
+70 −0
Original line number Diff line number Diff line
// Copyright (C) 2025 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 {
    default_team: "trendy_team_performance",
    default_applicable_licenses: ["Android-Apache-2.0"],
}

java_defaults {
    name: "structured_concurrency_perf_tests_defaults",
    defaults: [
        "platform_app_defaults",
        "SystemUI_optimized_defaults",
    ],
    srcs: [
        "src/**/*.kt",
    ],
    optimize: {
        proguard_flags_files: ["proguard.flags"],
    },
    static_libs: [
        "collector-device-lib",
        "tracinglib-platform",
        "kotlinx_coroutines_android",
        "kairos",
        "androidx.benchmark_benchmark-common",
        "androidx.benchmark_benchmark-junit4",
        "androidx.benchmark_benchmark-macro",
        // benchmark-macro includes a copy of the trace_processor_shell
        // binary, which will be run on device to create metrics
        "androidx.benchmark_benchmark-macro-junit4",
        "androidx.benchmark_benchmark-traceprocessor",
    ],
    test_suites: ["performance-tests"],
    platform_apis: true,
    certificate: "platform",
    use_resource_processor: true,
}

android_test {
    name: "StructuredConcurrencyPerfTests",
    defaults: [
        "structured_concurrency_perf_tests_defaults",
    ],
}

android_test {
    name: "StructuredConcurrencyPerfTests-debug",
    defaults: [
        "structured_concurrency_perf_tests_defaults",
    ],
    test_config: "AndroidTest-debug.xml",
    srcs: [
        "src-debug/**/*.kt",
    ],
    exclude_srcs: [
        "src/com/android/app/concurrent/benchmark/util/Constants.kt",
    ],
}
+27 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2025 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.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.app.concurrent.benchmark">

    <application android:networkSecurityConfig="@xml/network_security_config" />

    <instrumentation
        android:name="androidx.benchmark.junit4.AndroidBenchmarkRunner"
        android:label="Performance tests for various styles of structured concurrency"
        android:targetPackage="com.android.app.concurrent.benchmark" />

</manifest>
+81 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2025 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.
-->
<configuration description="Runs StructuredConcurrencyPerfTests metric instrumentation.">
    <!-- Declare as a performance test module -->
    <option name="config-descriptor:metadata" key="test-type" value="performance" />
    <option name="test-tag" value="structured-concurrency-perf-test" />

    <!-- Needed for storing the perfetto trace files in the sdcard/test_results-->
    <option name="isolated-storage" value="false"/>

    <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer"/>
    <target_preparer class="com.android.tradefed.targetprep.DeviceSetup">
        <option name="airplane-mode" value="on" />
        <option name="wifi" value="off" />
        <option name="bluetooth" value="off" />
        <option name="nfc" value="off" />
        <option name="screen-adaptive-brightness" value="off" />
        <option name="screen-always-on" value="on" />
    </target_preparer>

    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
        <option name="cleanup-apks" value="true" />
        <option name="test-file-name" value="StructuredConcurrencyPerfTests-debug.apk" />
    </target_preparer>

    <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
        <!-- perf-setup.sh is pre-installed on eng and userdebug builds -->
        <option name="run-command" value="perf-setup.sh" />
        <option name="run-command" value="pm compile -m speed -f com.android.app.concurrent.benchmark" />
        <option name="run-command" value="cat /dev/cpuset/camera-daemon-high-group/cpus > /dev/cpuset/top-app/cpus" />
        <option name="throw-if-cmd-fail" value="true" />
    </target_preparer>

    <metrics_collector class="com.android.tradefed.device.metric.PerfettoFilePullerCollector">
        <option name="pull-pattern-keys" value="additionalTestOutputFile_.*"/>
        <!-- Collect the files on each test case ended. Otherwise, traces of sibling tests will
             be associated with each test, and 2) additionalTestOutputFile_profiling_trace
             will be overwritten by subsequent test runs, meaning we'll only get one
             profiling trace for whatever ran last -->
        <option name="collect-on-run-ended-only" value="false"/>
        <!-- Don't clean up the file after pulling. Otherwise, the removal of the file from the last
             test may overlap with execution of the next test, causing inconsistent results. The
             benchmark runner will clean up the test output directory at the beginning of each test
             module. -->
        <option name="clean-up" value="false"/>
    </metrics_collector>

    <!-- Pull test metric results summary file from device to host -->
    <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
        <option name="pull-pattern-keys" value="metricSummaryOutputFile"/>
        <option name="clean-up" value="false" />
    </metrics_collector>

    <metric_post_processor class="com.android.tradefed.postprocessor.MetricFilePostProcessor">
        <option name="enable-per-test-log" value="true" />
        <option name="strict-include-metric-filter" value="(perfetto_mt|time_nanos|allocation_count)_.*" />
    </metric_post_processor>

    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
        <option name="package" value="com.android.app.concurrent.benchmark" />
        <option name="runner" value="androidx.benchmark.junit4.AndroidBenchmarkRunner" />
        <option name="device-listeners" value="com.android.app.concurrent.benchmark.util.CsvMetricCollector" />
        <option name="instrumentation-arg" key="csv-metric-collector:per_run" value="true" />
        <option name="instrumentation-arg" key="androidx.benchmark.profiling.mode" value="None" />
        <option name="instrumentation-arg" key="androidx.benchmark.iterations" value="50" />
        <option name="instrumentation-arg" key="androidx.benchmark.zipTraceWithInMemoryEvents.enable" value="true" />
    </test>
</configuration>
+91 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2025 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.
-->
<configuration description="Runs StructuredConcurrencyPerfTests metric instrumentation.">
    <!-- Declare as a performance test module -->
    <option name="config-descriptor:metadata" key="test-type" value="performance" />
    <option name="test-tag" value="structured-concurrency-perf-test" />

    <!-- Needed for storing the perfetto trace files in the sdcard/test_results-->
    <option name="isolated-storage" value="false"/>

    <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer"/>
    <target_preparer class="com.android.tradefed.targetprep.DeviceSetup">
        <option name="airplane-mode" value="on" />
        <option name="wifi" value="off" />
        <option name="bluetooth" value="off" />
        <option name="nfc" value="off" />
        <option name="screen-adaptive-brightness" value="off" />
        <option name="screen-always-on" value="on" />
    </target_preparer>

    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
        <option name="cleanup-apks" value="true" />
        <option name="test-file-name" value="StructuredConcurrencyPerfTests.apk" />
    </target_preparer>

    <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
        <!-- perf-setup.sh is pre-installed on eng and userdebug builds -->
        <option name="run-command" value="perf-setup.sh" />
        <option name="run-command" value="pm compile -m speed -f com.android.app.concurrent.benchmark" />
        <option name="run-command" value="cat /dev/cpuset/camera-daemon-high-group/cpus > /dev/cpuset/top-app/cpus" />
        <option name="throw-if-cmd-fail" value="true" />
    </target_preparer>

    <metrics_collector class="com.android.tradefed.device.metric.PerfettoFilePullerCollector">
        <option name="pull-pattern-keys" value="additionalTestOutputFile_.*"/>
        <!-- Collect the files on each test case ended. Otherwise, traces of sibling tests will
             be associated with each test, and 2) additionalTestOutputFile_profiling_trace
             will be overwritten by subsequent test runs, meaning we'll only get one
             profiling trace for whatever ran last -->
        <option name="collect-on-run-ended-only" value="false"/>
        <!-- Don't clean up the file after pulling. Otherwise, the removal of the file from the last
             test may overlap with execution of the next test, causing inconsistent results. The
             benchmark runner will clean up the test output directory at the beginning of each test
             module. -->
        <option name="clean-up" value="false"/>
    </metrics_collector>

    <!-- Pull test metric results summary file from device to host -->
    <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
        <option name="pull-pattern-keys" value="metricSummaryOutputFile"/>
        <option name="clean-up" value="false" />
    </metrics_collector>

    <metric_post_processor class="com.android.tradefed.postprocessor.MetricFilePostProcessor">
        <option name="enable-per-test-log" value="true" />
        <option name="strict-include-metric-filter" value="(perfetto_mt|time_nanos|allocation_count)_.*" />
    </metric_post_processor>

    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
        <option name="package" value="com.android.app.concurrent.benchmark" />
        <option name="runner" value="androidx.benchmark.junit4.AndroidBenchmarkRunner" />
        <option name="device-listeners" value="android.device.collectors.ProcLoadListener,com.android.app.concurrent.benchmark.util.CsvMetricCollector" />
        <!-- ProcLoadListener related arguments -->
        <!-- Wait for device last minute threshold to reach 1.0 with 180 second timeout before starting the test -->
        <option name="instrumentation-arg" key="proc-loadavg-threshold" value="1.0" />
        <option name="instrumentation-arg" key="proc-loadavg-timeout" value="180000" />
        <option name="instrumentation-arg" key="proc-loadavg-interval" value="5000" />
        <option name="instrumentation-arg" key="csv-metric-collector:per_run" value="true" />
        <option name="instrumentation-arg" key="androidx.benchmark.profiling.mode" value="None" />
        <option name="instrumentation-arg" key="androidx.benchmark.iterations" value="100" />
        <option name="instrumentation-arg" key="androidx.benchmark.zipTraceWithInMemoryEvents.enable" value="true" />
    </test>

    <!-- Reboot to undo perf-setup.sh -->
    <target_preparer class="com.android.tradefed.targetprep.DeviceCleaner">
        <option name="cleanup-action" value="REBOOT" />
    </target_preparer>
</configuration>
Loading