1 /*
2  * Copyright (C) 2018 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 #ifndef ART_TOOLS_DEXANALYZE_DEXANALYZE_STRINGS_H_
18 #define ART_TOOLS_DEXANALYZE_DEXANALYZE_STRINGS_H_
19 
20 #include <array>
21 #include <map>
22 #include <vector>
23 
24 #include "base/leb128.h"
25 #include "base/safe_map.h"
26 #include "dexanalyze_experiments.h"
27 #include "dex/code_item_accessors.h"
28 #include "dex/utf-inl.h"
29 
30 namespace art {
31 namespace dexanalyze {
32 
33 class StringTimings {
34  public:
35   void Dump(std::ostream& os) const;
36 
37   uint64_t time_equal_comparisons_ = 0u;
38   uint64_t time_non_equal_comparisons_ = 0u;
39   uint64_t num_comparisons_ = 0u;
40 };
41 
42 // Analyze string data and strings accessed from code.
43 class AnalyzeStrings : public Experiment {
44  public:
45   void ProcessDexFiles(const std::vector<std::unique_ptr<const DexFile>>& dex_files) override;
46   void Dump(std::ostream& os, uint64_t total_size) const override;
47 
48  private:
49   void ProcessStrings(const std::vector<std::string>& strings);
50   template <typename Strings> void Benchmark(const Strings& strings,
51                                              const std::vector<std::string>& reference,
52                                              StringTimings* timings);
53 
54   StringTimings prefix_timings_;
55   StringTimings normal_timings_;
56   int64_t wide_string_bytes_ = 0u;
57   int64_t ascii_string_bytes_ = 0u;
58   int64_t string_data_bytes_ = 0u;
59   int64_t total_unique_string_data_bytes_ = 0u;
60   int64_t total_shared_prefix_bytes_ = 0u;
61   int64_t total_prefix_savings_ = 0u;
62   int64_t total_prefix_dict_ = 0u;
63   int64_t total_prefix_table_ = 0u;
64   int64_t total_prefix_index_cost_ = 0u;
65   int64_t total_num_prefixes_ = 0u;
66   int64_t strings_used_prefixed_ = 0u;
67   int64_t short_strings_ = 0u;
68   int64_t long_strings_ = 0u;
69 };
70 
71 }  // namespace dexanalyze
72 }  // namespace art
73 
74 #endif  // ART_TOOLS_DEXANALYZE_DEXANALYZE_STRINGS_H_
75