• 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 = 20;
36     static constexpr uint32_t kMinNewClassesPercentChangeForCompilation = 20;
37 
Options()38     Options()
39         : force_merge_(kForceMergeDefault),
40           boot_image_merge_(kBootImageMergeDefault),
41           min_new_methods_percent_change_for_compilation_(
42               kMinNewMethodsPercentChangeForCompilation),
43           min_new_classes_percent_change_for_compilation_(
44               kMinNewClassesPercentChangeForCompilation) {
45     }
46 
IsForceMerge()47     bool IsForceMerge() const { return force_merge_; }
IsBootImageMerge()48     bool IsBootImageMerge() const { return boot_image_merge_; }
GetMinNewMethodsPercentChangeForCompilation()49     uint32_t GetMinNewMethodsPercentChangeForCompilation() const {
50         return min_new_methods_percent_change_for_compilation_;
51     }
GetMinNewClassesPercentChangeForCompilation()52     uint32_t GetMinNewClassesPercentChangeForCompilation() const {
53         return min_new_classes_percent_change_for_compilation_;
54     }
55 
SetForceMerge(bool value)56     void SetForceMerge(bool value) { force_merge_ = value; }
SetBootImageMerge(bool value)57     void SetBootImageMerge(bool value) { boot_image_merge_ = value; }
SetMinNewMethodsPercentChangeForCompilation(uint32_t value)58     void SetMinNewMethodsPercentChangeForCompilation(uint32_t value) {
59       min_new_methods_percent_change_for_compilation_ = value;
60     }
SetMinNewClassesPercentChangeForCompilation(uint32_t value)61     void SetMinNewClassesPercentChangeForCompilation(uint32_t value) {
62       min_new_classes_percent_change_for_compilation_ = value;
63     }
64 
65    private:
66     // If true, performs a forced merge, without analyzing if there is a
67     // significant difference between the current profile and the reference profile.
68     // See ProfileAssistant#ProcessProfile.
69     bool force_merge_;
70     // Signals that the merge is for boot image profiles. It will ignore differences
71     // in profile versions (instead of aborting).
72     bool boot_image_merge_;
73     uint32_t min_new_methods_percent_change_for_compilation_;
74     uint32_t min_new_classes_percent_change_for_compilation_;
75   };
76 
77   // Process the profile information present in the given files. Returns one of
78   // ProcessingResult values depending on profile information and whether or not
79   // the analysis ended up successfully (i.e. no errors during reading,
80   // merging or writing of profile files).
81   //
82   // When the returned value is kCompile there is a significant difference
83   // between profile_files and reference_profile_files. In this case
84   // reference_profile will be updated with the profiling info obtain after
85   // merging all profiles.
86   //
87   // When the returned value is kSkipCompilationSmallDelta, the difference between
88   // the merge of the current profiles and the reference one is insignificant. In
89   // this case no file will be updated. A variation of this code is
90   // kSkipCompilationEmptyProfiles which indicates that all the profiles are empty.
91   // This allow the caller to make fine grain decisions on the compilation strategy.
92   static ProfmanResult::ProcessingResult ProcessProfiles(
93       const std::vector<std::string>& profile_files,
94       const std::string& reference_profile_file,
95       const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn
96           = ProfileCompilationInfo::ProfileFilterFnAcceptAll,
97       const Options& options = Options());
98 
99   static ProfmanResult::ProcessingResult ProcessProfiles(
100       const std::vector<int>& profile_files_fd_,
101       int reference_profile_file_fd,
102       const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn
103           = ProfileCompilationInfo::ProfileFilterFnAcceptAll,
104       const Options& options = Options());
105 
106  private:
107   static ProfmanResult::ProcessingResult ProcessProfilesInternal(
108       const std::vector<ScopedFlock>& profile_files,
109       const ScopedFlock& reference_profile_file,
110       const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn,
111       const Options& options);
112 
113   DISALLOW_COPY_AND_ASSIGN(ProfileAssistant);
114 };
115 
116 }  // namespace art
117 
118 #endif  // ART_PROFMAN_PROFILE_ASSISTANT_H_
119