• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "androidfw/AssetManager.h"
18 #include "androidfw/ResourceTypes.h"
19 #include "android-base/file.h"
20 
21 #include "BenchmarkHelpers.h"
22 #include "data/sparse/R.h"
23 
24 namespace sparse = com::android::sparse;
25 
26 namespace android {
27 
BM_SparseEntryGetResourceHelper(const std::vector<std::string> & paths,uint32_t resid,benchmark::State & state,void (* GetResourceBenchmarkFunc)(const std::vector<std::string> &,const ResTable_config *,uint32_t,benchmark::State &))28 static void BM_SparseEntryGetResourceHelper(const std::vector<std::string>& paths,
29                     uint32_t resid, benchmark::State& state, void (*GetResourceBenchmarkFunc)(
30                     const std::vector<std::string>&, const ResTable_config*,
31                     uint32_t, benchmark::State&)){
32     ResTable_config config;
33     memset(&config, 0, sizeof(config));
34     config.orientation = ResTable_config::ORIENTATION_LAND;
35     GetResourceBenchmarkFunc(paths, &config, resid, state);
36 }
37 
BM_SparseEntryGetResourceOldSparse(benchmark::State & state,uint32_t resid)38 static void BM_SparseEntryGetResourceOldSparse(benchmark::State& state, uint32_t resid) {
39   BM_SparseEntryGetResourceHelper({GetTestDataPath() + "/sparse/sparse.apk"}, resid,
40                                     state, &GetResourceBenchmarkOld);
41 }
42 BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldSparse, Small, sparse::R::integer::foo_9);
43 BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldSparse, Large, sparse::R::string::foo_999);
44 
BM_SparseEntryGetResourceOldNotSparse(benchmark::State & state,uint32_t resid)45 static void BM_SparseEntryGetResourceOldNotSparse(benchmark::State& state, uint32_t resid) {
46    BM_SparseEntryGetResourceHelper({GetTestDataPath() + "/sparse/not_sparse.apk"}, resid,
47                                    state, &GetResourceBenchmarkOld);
48 }
49 BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldNotSparse, Small, sparse::R::integer::foo_9);
50 BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldNotSparse, Large, sparse::R::string::foo_999);
51 
BM_SparseEntryGetResourceSparse(benchmark::State & state,uint32_t resid)52 static void BM_SparseEntryGetResourceSparse(benchmark::State& state, uint32_t resid) {
53   BM_SparseEntryGetResourceHelper({GetTestDataPath() + "/sparse/sparse.apk"}, resid,
54                                   state, &GetResourceBenchmark);
55 }
56 BENCHMARK_CAPTURE(BM_SparseEntryGetResourceSparse, Small, sparse::R::integer::foo_9);
57 BENCHMARK_CAPTURE(BM_SparseEntryGetResourceSparse, Large, sparse::R::string::foo_999);
58 
BM_SparseEntryGetResourceNotSparse(benchmark::State & state,uint32_t resid)59 static void BM_SparseEntryGetResourceNotSparse(benchmark::State& state, uint32_t resid) {
60   BM_SparseEntryGetResourceHelper({GetTestDataPath() + "/sparse/not_sparse.apk"}, resid,
61                                   state, &GetResourceBenchmark);
62 }
63 BENCHMARK_CAPTURE(BM_SparseEntryGetResourceNotSparse, Small, sparse::R::integer::foo_9);
64 BENCHMARK_CAPTURE(BM_SparseEntryGetResourceNotSparse, Large, sparse::R::string::foo_999);
65 
BM_SparseEntryGetResourceOldSparseRuntime(benchmark::State & state,uint32_t resid)66 static void BM_SparseEntryGetResourceOldSparseRuntime(benchmark::State& state, uint32_t resid) {
67   BM_SparseEntryGetResourceHelper({base::GetExecutableDirectory() +
68                                   "/FrameworkResourcesSparseTestApp.apk"}, resid, state,
69                                   &GetResourceBenchmarkOld);
70 }
71 BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldSparseRuntime, Small, sparse::R::integer::foo_9);
72 BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldSparseRuntime, Large, sparse::R::string::foo_999);
73 
BM_SparseEntryGetResourceOldNotSparseRuntime(benchmark::State & state,uint32_t resid)74 static void BM_SparseEntryGetResourceOldNotSparseRuntime(benchmark::State& state, uint32_t resid) {
75   BM_SparseEntryGetResourceHelper({base::GetExecutableDirectory() +
76                                   "/FrameworkResourcesNotSparseTestApp.apk"}, resid, state,
77                                   &GetResourceBenchmarkOld);
78 }
79 BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldNotSparseRuntime, Small, sparse::R::integer::foo_9);
80 BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldNotSparseRuntime, Large, sparse::R::string::foo_999);
81 
BM_SparseEntryGetResourceSparseRuntime(benchmark::State & state,uint32_t resid)82 static void BM_SparseEntryGetResourceSparseRuntime(benchmark::State& state, uint32_t resid) {
83   BM_SparseEntryGetResourceHelper({base::GetExecutableDirectory() +
84                                   "/FrameworkResourcesSparseTestApp.apk"}, resid, state,
85                                   &GetResourceBenchmark);
86 }
87 BENCHMARK_CAPTURE(BM_SparseEntryGetResourceSparseRuntime, Small, sparse::R::integer::foo_9);
88 BENCHMARK_CAPTURE(BM_SparseEntryGetResourceSparseRuntime, Large, sparse::R::string::foo_999);
89 
BM_SparseEntryGetResourceNotSparseRuntime(benchmark::State & state,uint32_t resid)90 static void BM_SparseEntryGetResourceNotSparseRuntime(benchmark::State& state, uint32_t resid) {
91   BM_SparseEntryGetResourceHelper({base::GetExecutableDirectory() +
92                                   "/FrameworkResourcesNotSparseTestApp.apk"}, resid, state,
93                                   &GetResourceBenchmark);
94 }
95 BENCHMARK_CAPTURE(BM_SparseEntryGetResourceNotSparseRuntime, Small, sparse::R::integer::foo_9);
96 BENCHMARK_CAPTURE(BM_SparseEntryGetResourceNotSparseRuntime, Large, sparse::R::string::foo_999);
97 
98 }  // namespace android
99