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

Commit 72464747 authored by Yurii Zubrytskyi's avatar Yurii Zubrytskyi
Browse files

[res] Add a Theme::Rebase() benchmark + fix data

- Create a new benchmark targeting the Theme::Rebase() method
  specifically

- Fix the benchmark data so it doesn't try to run every data
  apk as a test on the device, and include the missing projects

- A minor style improvement

Flag: NONE A set of benchmark improvements
Bug: 345562237
Test: build, boot, atest + performance tests

Change-Id: If9d92a288ec9513ef9cefbb77490a49d4fb8d596
parent 31e9a622
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -267,6 +267,7 @@ cc_test {
cc_benchmark {
    name: "libandroidfw_benchmarks",
    defaults: ["libandroidfw_defaults"],
    test_config: "tests/AndroidTest_Benchmarks.xml",
    srcs: [
        // Helpers/infra for benchmarking.
        "tests/BenchMain.cpp",
@@ -282,7 +283,11 @@ cc_benchmark {
        "tests/Theme_bench.cpp",
    ],
    shared_libs: common_test_libs,
    data: ["tests/data/**/*.apk"],
    data: [
        "tests/data/**/*.apk",
        ":FrameworkResourcesSparseTestApp",
        ":FrameworkResourcesNotSparseTestApp",
    ],
}

cc_library {
+2 −2
Original line number Diff line number Diff line
@@ -280,9 +280,9 @@ class AssetManager2 {

   private:
    SelectedValue(uint8_t value_type, Res_value::data_type value_data, ApkAssetsCookie cookie,
                  uint32_t type_flags, uint32_t resid, const ResTable_config& config) :
                  uint32_t type_flags, uint32_t resid, ResTable_config config) :
                  cookie(cookie), data(value_data), type(value_type), flags(type_flags),
                  resid(resid), config(config) {};
                  resid(resid), config(std::move(config)) {}
  };

  // Retrieves the best matching resource value with ID `resid`.
+32 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<configuration description="Runs libandroidfw_benchmarks and libandroidfw_tests.">
    <option name="test-suite-tag" value="apct" />
    <option name="test-suite-tag" value="apct-native-metric" />

    <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
        <option name="cleanup" value="true" />
        <option name="push" value="libandroidfw_benchmarks->/data/local/tmp/libandroidfw_benchmarks" />
    </target_preparer>
    <test class="com.android.tradefed.testtype.GoogleBenchmarkTest" >
        <option name="native-benchmark-device-path" value="/data/local/tmp" />
        <option name="benchmark-module-name" value="libandroidfw_benchmarks" />
        <!-- The GoogleBenchmarkTest class ordinarily expects every file in the benchmark's
             directory (recursively) to be a google-benchmark binary, so we need this setting to
             avoid failing on the test data files. -->
        <option name="file-exclusion-filter-regex" value=".*\.(apk|config)$"  />
    </test>
</configuration>
 No newline at end of file
+10 −10
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ constexpr const static char* kFrameworkPath = "/system/framework/framework-res.a

static void BM_AssetManagerLoadAssets(benchmark::State& state) {
  std::string path = GetTestDataPath() + "/basic/basic.apk";
  while (state.KeepRunning()) {
  for (auto&& _ : state) {
    auto apk = ApkAssets::Load(path);
    AssetManager2 assets;
    assets.SetApkAssets({apk});
@@ -47,7 +47,7 @@ BENCHMARK(BM_AssetManagerLoadAssets);

static void BM_AssetManagerLoadAssetsOld(benchmark::State& state) {
  String8 path((GetTestDataPath() + "/basic/basic.apk").data());
  while (state.KeepRunning()) {
  for (auto&& _ : state) {
    AssetManager assets;
    assets.addAssetPath(path, nullptr /* cookie */, false /* appAsLib */,
                        false /* isSystemAsset */);
@@ -60,7 +60,7 @@ BENCHMARK(BM_AssetManagerLoadAssetsOld);

static void BM_AssetManagerLoadFrameworkAssets(benchmark::State& state) {
  std::string path = kFrameworkPath;
  while (state.KeepRunning()) {
  for (auto&& _ : state) {
    auto apk = ApkAssets::Load(path);
    AssetManager2 assets;
    assets.SetApkAssets({apk});
@@ -70,7 +70,7 @@ BENCHMARK(BM_AssetManagerLoadFrameworkAssets);

static void BM_AssetManagerLoadFrameworkAssetsOld(benchmark::State& state) {
  String8 path(kFrameworkPath);
  while (state.KeepRunning()) {
  for (auto&& _ : state) {
    AssetManager assets;
    assets.addAssetPath(path, nullptr /* cookie */, false /* appAsLib */,
                        false /* isSystemAsset */);
@@ -138,7 +138,7 @@ static void BM_AssetManagerGetBag(benchmark::State& state) {
  AssetManager2 assets;
  assets.SetApkAssets({apk});

  while (state.KeepRunning()) {
  for (auto&& _ : state) {
    auto bag = assets.GetBag(app::R::style::StyleTwo);
    if (!bag.has_value()) {
      state.SkipWithError("Failed to load get bag");
@@ -165,7 +165,7 @@ static void BM_AssetManagerGetBagOld(benchmark::State& state) {

  const ResTable& table = assets.getResources(true);

  while (state.KeepRunning()) {
  for (auto&& _ : state) {
    const ResTable::bag_entry* bag_begin;
    const ssize_t N = table.lockBag(app::R::style::StyleTwo, &bag_begin);
    const ResTable::bag_entry* const bag_end = bag_begin + N;
@@ -190,7 +190,7 @@ static void BM_AssetManagerGetResourceLocales(benchmark::State& state) {
  AssetManager2 assets;
  assets.SetApkAssets({apk});

  while (state.KeepRunning()) {
  for (auto&& _ : state) {
    std::set<std::string> locales =
        assets.GetResourceLocales(false /*exclude_system*/, true /*merge_equivalent_languages*/);
    benchmark::DoNotOptimize(locales);
@@ -208,7 +208,7 @@ static void BM_AssetManagerGetResourceLocalesOld(benchmark::State& state) {

  const ResTable& table = assets.getResources(true);

  while (state.KeepRunning()) {
  for (auto&& _ : state) {
    Vector<String8> locales;
    table.getLocales(&locales, true /*includeSystemLocales*/, true /*mergeEquivalentLangs*/);
    benchmark::DoNotOptimize(locales);
@@ -231,7 +231,7 @@ static void BM_AssetManagerSetConfigurationFramework(benchmark::State& state) {
  std::vector<ResTable_config> configs;
  configs.push_back(config);

  while (state.KeepRunning()) {
  for (auto&& _ : state) {
    configs[0].sdkVersion = ~configs[0].sdkVersion;
    assets.SetConfigurations(configs);
  }
@@ -251,7 +251,7 @@ static void BM_AssetManagerSetConfigurationFrameworkOld(benchmark::State& state)
  ResTable_config config;
  memset(&config, 0, sizeof(config));

  while (state.KeepRunning()) {
  for (auto&& _ : state) {
    config.sdkVersion = ~config.sdkVersion;
    assets.setConfiguration(config);
  }
+2 −2
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ void GetResourceBenchmarkOld(const std::vector<std::string>& paths, const ResTab
  for (const std::string& path : paths) {
    if (!assetmanager.addAssetPath(String8(path.c_str()), nullptr /* cookie */,
                                   false /* appAsLib */, false /* isSystemAssets */)) {
      state.SkipWithError(base::StringPrintf("Failed to load assets %s", path.c_str()).c_str());
      state.SkipWithError(base::StringPrintf("Failed to old-load assets %s", path.c_str()).c_str());
      return;
    }
  }
@@ -57,7 +57,7 @@ void GetResourceBenchmark(const std::vector<std::string>& paths, const ResTable_
  for (const std::string& path : paths) {
    auto apk = ApkAssets::Load(path);
    if (apk == nullptr) {
      state.SkipWithError(base::StringPrintf("Failed to load assets %s", path.c_str()).c_str());
      state.SkipWithError(base::StringPrintf("Failed to new-load assets %s", path.c_str()).c_str());
      return;
    }
    apk_assets.push_back(std::move(apk));
Loading