From a1e42b09503f181c3ffcd56543c4c0e4a40f2485 Mon Sep 17 00:00:00 2001 From: Zhi Dou Date: Fri, 20 Dec 2024 16:45:27 +0000 Subject: add Aconfig perf test This commit creates new folder for aconfig perf tests. It adds perf tests for AconfigPacage. Test: atest AconfigPerfTests Bug: 383740537 Change-Id: If71c1eec19b074dbc8306ca92ff77fe468cb9ebc --- apct-tests/perftests/aconfig/Android.bp | 39 ++++++ apct-tests/perftests/aconfig/AndroidManifest.xml | 27 ++++ apct-tests/perftests/aconfig/AndroidTest.xml | 63 ++++++++++ apct-tests/perftests/aconfig/OWNERS | 1 + .../os/flagging/AconfigPackagePerfTest.java | 139 +++++++++++++++++++++ 5 files changed, 269 insertions(+) create mode 100644 apct-tests/perftests/aconfig/Android.bp create mode 100644 apct-tests/perftests/aconfig/AndroidManifest.xml create mode 100644 apct-tests/perftests/aconfig/AndroidTest.xml create mode 100644 apct-tests/perftests/aconfig/OWNERS create mode 100644 apct-tests/perftests/aconfig/src/android/os/flagging/AconfigPackagePerfTest.java diff --git a/apct-tests/perftests/aconfig/Android.bp b/apct-tests/perftests/aconfig/Android.bp new file mode 100644 index 000000000000..715923de1eb7 --- /dev/null +++ b/apct-tests/perftests/aconfig/Android.bp @@ -0,0 +1,39 @@ +// Copyright (C) 2024 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_android_core_experiments", + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "frameworks_base_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["frameworks_base_license"], +} + +android_test { + name: "AconfigPerfTests", + srcs: ["src/**/*.java"], + static_libs: [ + "aconfig_device_paths_java_util", + "androidx.test.rules", + "apct-perftests-utils", + "collector-device-lib", + "truth", + ], + platform_apis: true, + certificate: "platform", + test_suites: ["device-tests"], + data: [":perfetto_artifacts"], +} diff --git a/apct-tests/perftests/aconfig/AndroidManifest.xml b/apct-tests/perftests/aconfig/AndroidManifest.xml new file mode 100644 index 000000000000..e9d7c176303f --- /dev/null +++ b/apct-tests/perftests/aconfig/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/apct-tests/perftests/aconfig/AndroidTest.xml b/apct-tests/perftests/aconfig/AndroidTest.xml new file mode 100644 index 000000000000..036e0310def2 --- /dev/null +++ b/apct-tests/perftests/aconfig/AndroidTest.xml @@ -0,0 +1,63 @@ + + + + \ No newline at end of file diff --git a/apct-tests/perftests/aconfig/OWNERS b/apct-tests/perftests/aconfig/OWNERS new file mode 100644 index 000000000000..2202076593fb --- /dev/null +++ b/apct-tests/perftests/aconfig/OWNERS @@ -0,0 +1 @@ +file:platform/packages/modules/ConfigInfrastructure:/OWNERS \ No newline at end of file diff --git a/apct-tests/perftests/aconfig/src/android/os/flagging/AconfigPackagePerfTest.java b/apct-tests/perftests/aconfig/src/android/os/flagging/AconfigPackagePerfTest.java new file mode 100644 index 000000000000..df6e3c836256 --- /dev/null +++ b/apct-tests/perftests/aconfig/src/android/os/flagging/AconfigPackagePerfTest.java @@ -0,0 +1,139 @@ +/* + * Copyright 2024 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 android.os.flagging; + +import static com.google.common.truth.Truth.assertThat; + +import android.aconfig.DeviceProtosTestUtil; +import android.aconfig.nano.Aconfig.parsed_flag; +import android.perftests.utils.BenchmarkState; +import android.perftests.utils.PerfStatusReporter; + +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +@RunWith(Parameterized.class) +public class AconfigPackagePerfTest { + + @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); + + @Parameterized.Parameters(name = "isPlatform={0}") + public static Collection data() { + return Arrays.asList(new Object[][] {{false}, {true}}); + } + + private static final Set PLATFORM_CONTAINERS = Set.of("system", "vendor", "product"); + private static List sFlags; + + @BeforeClass + public static void init() { + try { + sFlags = DeviceProtosTestUtil.loadAndParseFlagProtos(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Parameterized.Parameter(0) + + // if this variable is true, then the test query flags from system/product/vendor + // if this variable is false, then the test query flags from updatable partitions + public boolean mIsPlatform; + + @Test + public void timeAconfigPackageLoadOnePackage() { + String packageName = ""; + for (parsed_flag flag : sFlags) { + if (mIsPlatform == PLATFORM_CONTAINERS.contains(flag.container)) { + packageName = flag.package_; + break; + } + } + BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + while (state.keepRunning()) { + AconfigPackage.load(packageName); + } + } + + @Test + public void timeAconfigPackageLoadMultiplePackages() { + // load num packages + int packageNum = 25; + Set packageSet = new HashSet<>(); + for (parsed_flag flag : sFlags) { + if (mIsPlatform == PLATFORM_CONTAINERS.contains(flag.container)) { + packageSet.add(flag.package_); + } + if (packageSet.size() >= packageNum) { + break; + } + } + List packageList = new ArrayList(packageSet); + assertThat(packageList.size()).isAtLeast(packageNum); + BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + for (int i = 0; state.keepRunning(); i++) { + AconfigPackage.load(packageList.get(i % packageNum)); + } + } + + @Test + public void timeAconfigPackageGetBooleanFlagValue() { + // get one package contains num of flags + int flagNum = 20; + List l = findNumFlagsInSamePackage(flagNum, mIsPlatform); + List flagName = new ArrayList<>(); + String packageName = l.get(0).package_; + for (parsed_flag flag : l) { + flagName.add(flag.name); + } + assertThat(flagName.size()).isAtLeast(flagNum); + BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + AconfigPackage ap = AconfigPackage.load(packageName); + for (int i = 0; state.keepRunning(); i++) { + ap.getBooleanFlagValue(flagName.get(i % flagNum), false); + } + } + + private static List findNumFlagsInSamePackage(int num, boolean isPlatform) { + Map> packageToFlag = new HashMap<>(); + List ret = new ArrayList(); + for (parsed_flag flag : sFlags) { + if (isPlatform == PLATFORM_CONTAINERS.contains(flag.container)) { + ret = + packageToFlag.computeIfAbsent( + flag.package_, k -> new ArrayList()); + ret.add(flag); + if (ret.size() >= num) { + break; + } + } + } + return ret; + } +} -- cgit v1.2.3-59-g8ed1b