• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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_PROFILE_ASSISTANT_H_
18 #define ART_PROFMAN_PROFILE_ASSISTANT_H_
19 
20 #include <string>
21 #include <vector>
22 
23 #include "base/scoped_flock.h"
24 #include "profile/profile_compilation_info.h"
25 #include "profman/profman_result.h"
26 
27 namespace art {
28 
29 class ProfileAssistant {
30  public:
31   class Options {
32    public:
33     static constexpr bool kForceMergeDefault = false;
34     static constexpr bool kBootImageMergeDefault = false;
35     static constexpr uint32_t kMinNewMethodsPercentChangeForCompilation = 2;
36     static constexpr uint32_t kMinNewClassesPercentChangeForCompilation = 2;
37 
Options()38     Options()
39         : force_merge_(kForceMergeDefault),
40           force_merge_and_analyze_(kForceMergeDefault),
41           boot_image_merge_(kBootImageMergeDefault),
42           min_new_methods_percent_change_for_compilation_(
43               kMinNewMethodsPercentChangeForCompilation),
44           min_new_classes_percent_change_for_compilation_(
45               kMinNewClassesPercentChangeForCompilation) {
46     }
47 
48     // Only for S and T uses. U+ should use `IsForceMergeAndAnalyze`.
IsForceMerge()49     bool IsForceMerge() const { return force_merge_; }
IsForceMergeAndAnalyze()50     bool IsForceMergeAndAnalyze() const { return force_merge_and_analyze_; }
IsBootImageMerge()51     bool IsBootImageMerge() const { return boot_image_merge_; }
GetMinNewMethodsPercentChangeForCompilation()52     uint32_t GetMinNewMethodsPercentChangeForCompilation() const {
53         return min_new_methods_percent_change_for_compilation_;
54     }
GetMinNewClassesPercentChangeForCompilation()55     uint32_t GetMinNewClassesPercentChangeForCompilation() const {
56         return min_new_classes_percent_change_for_compilation_;
57     }
58 
SetForceMerge(bool value)59     void SetForceMerge(bool value) { force_merge_ = value; }
SetForceMergeAndAnalyze(bool value)60     void SetForceMergeAndAnalyze(bool value) { force_merge_and_analyze_ = value; }
SetBootImageMerge(bool value)61     void SetBootImageMerge(bool value) { boot_image_merge_ = value; }
SetMinNewMethodsPercentChangeForCompilation(uint32_t value)62     void SetMinNewMethodsPercentChangeForCompilation(uint32_t value) {
63       min_new_methods_percent_change_for_compilation_ = value;
64     }
SetMinNewClassesPercentChangeForCompilation(uint32_t value)65     void SetMinNewClassesPercentChangeForCompilation(uint32_t value) {
66       min_new_classes_percent_change_for_compilation_ = value;
67     }
68 
69    private:
70     // If true, performs a forced merge, without analyzing if there is a significant difference
71     // between before and after the merge.
72     // See ProfileAssistant#ProcessProfile.
73     // Only for S and T uses. U+ should use `force_merge_and_analyze_`.
74     bool force_merge_;
75     // If true, performs a forced merge and analyzes if there is any difference between before and
76     // after the merge.
77     // See ProfileAssistant#ProcessProfile.
78     bool force_merge_and_analyze_;
79     // Signals that the merge is for boot image profiles. It will ignore differences
80     // in profile versions (instead of aborting).
81     bool boot_image_merge_;
82     uint32_t min_new_methods_percent_change_for_compilation_;
83     uint32_t min_new_classes_percent_change_for_compilation_;
84   };
85 
86   // Process the profile information present in the given files. Returns one of
87   // ProcessingResult values depending on profile information and whether or not
88   // the analysis ended up successfully (i.e. no errors during reading,
89   // merging or writing of profile files).
90   //
91   // When the returned value is kCompile there is a significant difference
92   // between profile_files and reference_profile_files. In this case
93   // reference_profile will be updated with the profiling info obtain after
94   // merging all profiles.
95   //
96   // When the returned value is kSkipCompilationSmallDelta, the difference between
97   // the merge of the current profiles and the reference one is insignificant. In
98   // this case no file will be updated. A variation of this code is
99   // kSkipCompilationEmptyProfiles which indicates that all the profiles are empty.
100   // This allow the caller to make fine grain decisions on the compilation strategy.
101   static ProfmanResult::ProcessingResult ProcessProfiles(
102       const std::vector<std::string>& profile_files,
103       const std::string& reference_profile_file,
104       const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn
105           = ProfileCompilationInfo::ProfileFilterFnAcceptAll,
106       const Options& options = Options());
107 
108   static ProfmanResult::ProcessingResult ProcessProfiles(
109       const std::vector<int>& profile_files_fd_,
110       int reference_profile_file_fd,
111       const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn
112           = ProfileCompilationInfo::ProfileFilterFnAcceptAll,
113       const Options& options = Options());
114 
115  private:
116   static ProfmanResult::ProcessingResult ProcessProfilesInternal(
117       const std::vector<ScopedFlock>& profile_files,
118       const ScopedFlock& reference_profile_file,
119       const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn,
120       const Options& options);
121 
122   DISALLOW_COPY_AND_ASSIGN(ProfileAssistant);
123 };
124 
125 }  // namespace art
126 
127 #endif  // ART_PROFMAN_PROFILE_ASSISTANT_H_
128