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 #ifndef ART_PROFMAN_BOOT_IMAGE_PROFILE_H_
18 #define ART_PROFMAN_BOOT_IMAGE_PROFILE_H_
19 
20 #include <limits>
21 #include <memory>
22 #include <vector>
23 #include <set>
24 
25 #include "base/safe_map.h"
26 #include "dex/dex_file.h"
27 
28 namespace art {
29 
30 class ProfileCompilationInfo;
31 
32 struct BootImageOptions {
33  public:
34   // Threshold for preloaded. The threshold specifies, as percentage
35   // of maximum number or aggregations, how many different profiles need to have the class
36   // before it gets added to the list of preloaded classes.
37   uint32_t preloaded_class_threshold = 10;
38 
39   // Threshold for classes that may be dirty or clean. The threshold specifies, as percentage
40   // of maximum number or aggregations, how many different profiles need to have the class
41   // before it gets added to the boot profile.
42   uint32_t image_class_threshold = 10;
43 
44   // Threshold for classes that are likely to remain clean. The threshold specifies, as percentage
45   // of maximum number or aggregations, how many different profiles need to have the class
46   // before it gets added to the boot profile.
47   uint32_t image_class_clean_threshold = 5;
48 
49   // Threshold for including a method in the profile. The threshold specifies, as percentage
50   // of maximum number or aggregations, how many different profiles need to have the method
51   // before it gets added to the boot profile.
52   uint32_t method_threshold = 10;
53 
54   // Whether or not we should upgrade the startup methods to hot.
55   bool upgrade_startup_to_hot = true;
56 
57   // A special set of thresholds (classes and methods) that apply if a method/class is being used
58   // by a special package. This can be used to lower the thresholds for methods used by important
59   // packages (e.g. system server of system ui) or packages which have special needs (e.g. camera
60   // needs more hardware methods).
61   SafeMap<std::string, uint32_t> special_packages_thresholds;
62 
63   // Whether or not to append package use list to each profile element.
64   // Should be use only for debugging as it will add additional elements to the text output
65   // that are not compatible with the default profile format.
66   bool append_package_use_list = false;
67 
68   // The set of classes that should not be preloaded in Zygote
69   std::set<std::string> preloaded_classes_blacklist;
70 };
71 
72 // Generate a boot image profile according to the specified options.
73 // Boot classpaths dex files are identified by the given vector and the output is
74 // written to the two specified paths. The paths will be open with O_CREAT | O_WRONLY.
75 // Returns true if the generation was successful, false otherwise.
76 bool GenerateBootImageProfile(
77     const std::vector<std::unique_ptr<const DexFile>>& dex_files,
78     const std::vector<std::string>& profile_files,
79     const BootImageOptions& options,
80     const std::string& boot_profile_out_path,
81     const std::string& preloaded_classes_out_path);
82 
83 }  // namespace art
84 
85 #endif  // ART_PROFMAN_BOOT_IMAGE_PROFILE_H_
86