summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yurii Zubrytskyi <zyy@google.com> 2024-06-24 19:16:52 -0700
committer Yurii Zubrytskyi <zyy@google.com> 2024-06-25 13:01:57 -0700
commit72464747c330bc656286cd3e545a0087f89a4559 (patch)
treead8217f3de7e4232717f1556d3471810e7dc46c8
parent31e9a622c62047b8fa109b8f060dce8cdb4785f8 (diff)
[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
-rw-r--r--libs/androidfw/Android.bp7
-rw-r--r--libs/androidfw/include/androidfw/AssetManager2.h4
-rw-r--r--libs/androidfw/tests/AndroidTest_Benchmarks.xml32
-rw-r--r--libs/androidfw/tests/AssetManager2_bench.cpp20
-rw-r--r--libs/androidfw/tests/BenchmarkHelpers.cpp4
-rw-r--r--libs/androidfw/tests/Theme_bench.cpp30
6 files changed, 82 insertions, 15 deletions
diff --git a/libs/androidfw/Android.bp b/libs/androidfw/Android.bp
index 77800a305f02..260f3c148841 100644
--- a/libs/androidfw/Android.bp
+++ b/libs/androidfw/Android.bp
@@ -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 {
diff --git a/libs/androidfw/include/androidfw/AssetManager2.h b/libs/androidfw/include/androidfw/AssetManager2.h
index 17a8ba6c03bd..ac46bc5c179f 100644
--- a/libs/androidfw/include/androidfw/AssetManager2.h
+++ b/libs/androidfw/include/androidfw/AssetManager2.h
@@ -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`.
diff --git a/libs/androidfw/tests/AndroidTest_Benchmarks.xml b/libs/androidfw/tests/AndroidTest_Benchmarks.xml
new file mode 100644
index 000000000000..e61e46fb7785
--- /dev/null
+++ b/libs/androidfw/tests/AndroidTest_Benchmarks.xml
@@ -0,0 +1,32 @@
+<?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
diff --git a/libs/androidfw/tests/AssetManager2_bench.cpp b/libs/androidfw/tests/AssetManager2_bench.cpp
index 2caa98c35971..136f5ea639a1 100644
--- a/libs/androidfw/tests/AssetManager2_bench.cpp
+++ b/libs/androidfw/tests/AssetManager2_bench.cpp
@@ -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);
}
diff --git a/libs/androidfw/tests/BenchmarkHelpers.cpp b/libs/androidfw/tests/BenchmarkHelpers.cpp
index 8b883f4ed1df..e3fc0a0a4e68 100644
--- a/libs/androidfw/tests/BenchmarkHelpers.cpp
+++ b/libs/androidfw/tests/BenchmarkHelpers.cpp
@@ -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));
diff --git a/libs/androidfw/tests/Theme_bench.cpp b/libs/androidfw/tests/Theme_bench.cpp
index dfbb5a76dec6..bf89617635cc 100644
--- a/libs/androidfw/tests/Theme_bench.cpp
+++ b/libs/androidfw/tests/Theme_bench.cpp
@@ -27,6 +27,10 @@ constexpr const static char* kFrameworkPath = "/system/framework/framework-res.a
constexpr const static uint32_t kStyleId = 0x01030237u; // android:style/Theme.Material.Light
constexpr const static uint32_t kAttrId = 0x01010030u; // android:attr/colorForeground
+constexpr const static uint32_t kStyle2Id = 0x01030224u; // android:style/Theme.Material
+constexpr const static uint32_t kStyle3Id = 0x0103024du; // android:style/Widget.Material
+constexpr const static uint32_t kStyle4Id = 0x0103028eu; // android:style/Widget.Material.Light
+
static void BM_ThemeApplyStyleFramework(benchmark::State& state) {
auto apk = ApkAssets::Load(kFrameworkPath);
if (apk == nullptr) {
@@ -61,6 +65,32 @@ static void BM_ThemeApplyStyleFrameworkOld(benchmark::State& state) {
}
BENCHMARK(BM_ThemeApplyStyleFrameworkOld);
+static void BM_ThemeRebaseFramework(benchmark::State& state) {
+ auto apk = ApkAssets::Load(kFrameworkPath);
+ if (apk == nullptr) {
+ state.SkipWithError("Failed to load assets");
+ return;
+ }
+
+ AssetManager2 assets;
+ assets.SetApkAssets({apk});
+
+ // Create two arrays of styles to switch between back and forth.
+ const uint32_t styles1[] = {kStyle2Id, kStyleId, kStyle3Id};
+ const uint8_t force1[std::size(styles1)] = {false, true, false};
+ const uint32_t styles2[] = {kStyleId, kStyle2Id, kStyle4Id, kStyle3Id};
+ const uint8_t force2[std::size(styles2)] = {false, true, true, false};
+ const auto theme = assets.NewTheme();
+ // Initialize the theme to make the first iteration the same as the rest.
+ theme->Rebase(&assets, styles1, force1, std::size(force1));
+
+ while (state.KeepRunning()) {
+ theme->Rebase(&assets, styles2, force2, std::size(force2));
+ theme->Rebase(&assets, styles1, force1, std::size(force1));
+ }
+}
+BENCHMARK(BM_ThemeRebaseFramework);
+
static void BM_ThemeGetAttribute(benchmark::State& state) {
auto apk = ApkAssets::Load(kFrameworkPath);