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