1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2018 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker #ifndef ART_TOOLS_DEXANALYZE_DEXANALYZE_STRINGS_H_ 18*795d594fSAndroid Build Coastguard Worker #define ART_TOOLS_DEXANALYZE_DEXANALYZE_STRINGS_H_ 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker #include <array> 21*795d594fSAndroid Build Coastguard Worker #include <map> 22*795d594fSAndroid Build Coastguard Worker #include <vector> 23*795d594fSAndroid Build Coastguard Worker 24*795d594fSAndroid Build Coastguard Worker #include "base/leb128.h" 25*795d594fSAndroid Build Coastguard Worker #include "base/safe_map.h" 26*795d594fSAndroid Build Coastguard Worker #include "dexanalyze_experiments.h" 27*795d594fSAndroid Build Coastguard Worker #include "dex/code_item_accessors.h" 28*795d594fSAndroid Build Coastguard Worker #include "dex/utf-inl.h" 29*795d594fSAndroid Build Coastguard Worker 30*795d594fSAndroid Build Coastguard Worker namespace art { 31*795d594fSAndroid Build Coastguard Worker namespace dexanalyze { 32*795d594fSAndroid Build Coastguard Worker 33*795d594fSAndroid Build Coastguard Worker class StringTimings { 34*795d594fSAndroid Build Coastguard Worker public: 35*795d594fSAndroid Build Coastguard Worker void Dump(std::ostream& os) const; 36*795d594fSAndroid Build Coastguard Worker 37*795d594fSAndroid Build Coastguard Worker uint64_t time_equal_comparisons_ = 0u; 38*795d594fSAndroid Build Coastguard Worker uint64_t time_non_equal_comparisons_ = 0u; 39*795d594fSAndroid Build Coastguard Worker uint64_t num_comparisons_ = 0u; 40*795d594fSAndroid Build Coastguard Worker }; 41*795d594fSAndroid Build Coastguard Worker 42*795d594fSAndroid Build Coastguard Worker // Analyze string data and strings accessed from code. 43*795d594fSAndroid Build Coastguard Worker class AnalyzeStrings : public Experiment { 44*795d594fSAndroid Build Coastguard Worker public: 45*795d594fSAndroid Build Coastguard Worker void ProcessDexFiles(const std::vector<std::unique_ptr<const DexFile>>& dex_files) override; 46*795d594fSAndroid Build Coastguard Worker void Dump(std::ostream& os, uint64_t total_size) const override; 47*795d594fSAndroid Build Coastguard Worker 48*795d594fSAndroid Build Coastguard Worker private: 49*795d594fSAndroid Build Coastguard Worker void ProcessStrings(const std::vector<std::string>& strings); 50*795d594fSAndroid Build Coastguard Worker template <typename Strings> void Benchmark(const Strings& strings, 51*795d594fSAndroid Build Coastguard Worker const std::vector<std::string>& reference, 52*795d594fSAndroid Build Coastguard Worker StringTimings* timings); 53*795d594fSAndroid Build Coastguard Worker 54*795d594fSAndroid Build Coastguard Worker StringTimings prefix_timings_; 55*795d594fSAndroid Build Coastguard Worker StringTimings normal_timings_; 56*795d594fSAndroid Build Coastguard Worker int64_t wide_string_bytes_ = 0u; 57*795d594fSAndroid Build Coastguard Worker int64_t ascii_string_bytes_ = 0u; 58*795d594fSAndroid Build Coastguard Worker int64_t string_data_bytes_ = 0u; 59*795d594fSAndroid Build Coastguard Worker int64_t total_unique_string_data_bytes_ = 0u; 60*795d594fSAndroid Build Coastguard Worker int64_t total_shared_prefix_bytes_ = 0u; 61*795d594fSAndroid Build Coastguard Worker int64_t total_prefix_savings_ = 0u; 62*795d594fSAndroid Build Coastguard Worker int64_t total_prefix_dict_ = 0u; 63*795d594fSAndroid Build Coastguard Worker int64_t total_prefix_table_ = 0u; 64*795d594fSAndroid Build Coastguard Worker int64_t total_prefix_index_cost_ = 0u; 65*795d594fSAndroid Build Coastguard Worker int64_t total_num_prefixes_ = 0u; 66*795d594fSAndroid Build Coastguard Worker int64_t strings_used_prefixed_ = 0u; 67*795d594fSAndroid Build Coastguard Worker int64_t short_strings_ = 0u; 68*795d594fSAndroid Build Coastguard Worker int64_t long_strings_ = 0u; 69*795d594fSAndroid Build Coastguard Worker }; 70*795d594fSAndroid Build Coastguard Worker 71*795d594fSAndroid Build Coastguard Worker } // namespace dexanalyze 72*795d594fSAndroid Build Coastguard Worker } // namespace art 73*795d594fSAndroid Build Coastguard Worker 74*795d594fSAndroid Build Coastguard Worker #endif // ART_TOOLS_DEXANALYZE_DEXANALYZE_STRINGS_H_ 75