• 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  * * See the License for the specific language governing permissions and
10  * limitations under the License.
11  */
12 
13 #ifndef ART_RUNTIME_JIT_PROFILE_SAVER_OPTIONS_H_
14 #define ART_RUNTIME_JIT_PROFILE_SAVER_OPTIONS_H_
15 
16 #include <string>
17 #include <ostream>
18 
19 namespace art {
20 
21 struct ProfileSaverOptions {
22  public:
23   static constexpr uint32_t kMinSavePeriodMs = 40 * 1000;  // 40 seconds
24   static constexpr uint32_t kSaveResolvedClassesDelayMs = 5 * 1000;  // 5 seconds
25   // Minimum number of JIT samples during launch to mark a method as hot in the profile.
26   static constexpr uint32_t kHotStartupMethodSamples = 1;
27   static constexpr uint32_t kHotStartupMethodSamplesLowRam = 256;
28   static constexpr uint32_t kMinMethodsToSave = 10;
29   static constexpr uint32_t kMinClassesToSave = 10;
30   static constexpr uint32_t kMinNotificationBeforeWake = 10;
31   static constexpr uint32_t kMaxNotificationBeforeWake = 50;
32   static constexpr uint32_t kHotStartupMethodSamplesNotSet = std::numeric_limits<uint32_t>::max();
33 
ProfileSaverOptionsProfileSaverOptions34   ProfileSaverOptions() :
35     enabled_(false),
36     min_save_period_ms_(kMinSavePeriodMs),
37     save_resolved_classes_delay_ms_(kSaveResolvedClassesDelayMs),
38     hot_startup_method_samples_(kHotStartupMethodSamplesNotSet),
39     min_methods_to_save_(kMinMethodsToSave),
40     min_classes_to_save_(kMinClassesToSave),
41     min_notification_before_wake_(kMinNotificationBeforeWake),
42     max_notification_before_wake_(kMaxNotificationBeforeWake),
43     profile_path_(""),
44     profile_boot_class_path_(false) {}
45 
ProfileSaverOptionsProfileSaverOptions46   ProfileSaverOptions(
47       bool enabled,
48       uint32_t min_save_period_ms,
49       uint32_t save_resolved_classes_delay_ms,
50       uint32_t hot_startup_method_samples,
51       uint32_t min_methods_to_save,
52       uint32_t min_classes_to_save,
53       uint32_t min_notification_before_wake,
54       uint32_t max_notification_before_wake,
55       const std::string& profile_path,
56       bool profile_boot_class_path)
57   : enabled_(enabled),
58     min_save_period_ms_(min_save_period_ms),
59     save_resolved_classes_delay_ms_(save_resolved_classes_delay_ms),
60     hot_startup_method_samples_(hot_startup_method_samples),
61     min_methods_to_save_(min_methods_to_save),
62     min_classes_to_save_(min_classes_to_save),
63     min_notification_before_wake_(min_notification_before_wake),
64     max_notification_before_wake_(max_notification_before_wake),
65     profile_path_(profile_path),
66     profile_boot_class_path_(profile_boot_class_path) {}
67 
IsEnabledProfileSaverOptions68   bool IsEnabled() const {
69     return enabled_;
70   }
SetEnabledProfileSaverOptions71   void SetEnabled(bool enabled) {
72     enabled_ = enabled;
73   }
74 
GetMinSavePeriodMsProfileSaverOptions75   uint32_t GetMinSavePeriodMs() const {
76     return min_save_period_ms_;
77   }
GetSaveResolvedClassesDelayMsProfileSaverOptions78   uint32_t GetSaveResolvedClassesDelayMs() const {
79     return save_resolved_classes_delay_ms_;
80   }
GetHotStartupMethodSamplesProfileSaverOptions81   uint32_t GetHotStartupMethodSamples(bool is_low_ram) const {
82     uint32_t ret = hot_startup_method_samples_;
83     if (ret == kHotStartupMethodSamplesNotSet) {
84       ret = is_low_ram ? kHotStartupMethodSamplesLowRam : kHotStartupMethodSamples;
85     }
86     return ret;
87   }
GetMinMethodsToSaveProfileSaverOptions88   uint32_t GetMinMethodsToSave() const {
89     return min_methods_to_save_;
90   }
GetMinClassesToSaveProfileSaverOptions91   uint32_t GetMinClassesToSave() const {
92     return min_classes_to_save_;
93   }
GetMinNotificationBeforeWakeProfileSaverOptions94   uint32_t GetMinNotificationBeforeWake() const {
95     return min_notification_before_wake_;
96   }
GetMaxNotificationBeforeWakeProfileSaverOptions97   uint32_t GetMaxNotificationBeforeWake() const {
98     return max_notification_before_wake_;
99   }
GetProfilePathProfileSaverOptions100   std::string GetProfilePath() const {
101     return profile_path_;
102   }
GetProfileBootClassPathProfileSaverOptions103   bool GetProfileBootClassPath() const {
104     return profile_boot_class_path_;
105   }
106 
107   friend std::ostream & operator<<(std::ostream &os, const ProfileSaverOptions& pso) {
108     os << "enabled_" << pso.enabled_
109         << ", min_save_period_ms_" << pso.min_save_period_ms_
110         << ", save_resolved_classes_delay_ms_" << pso.save_resolved_classes_delay_ms_
111         << ", hot_startup_method_samples_" << pso.hot_startup_method_samples_
112         << ", min_methods_to_save_" << pso.min_methods_to_save_
113         << ", min_classes_to_save_" << pso.min_classes_to_save_
114         << ", min_notification_before_wake_" << pso.min_notification_before_wake_
115         << ", max_notification_before_wake_" << pso.max_notification_before_wake_
116         << ", profile_boot_class_path_" << pso.profile_boot_class_path_;
117     return os;
118   }
119 
120   bool enabled_;
121   uint32_t min_save_period_ms_;
122   uint32_t save_resolved_classes_delay_ms_;
123   // Do not access hot_startup_method_samples_ directly for reading since it may be set to the
124   // placeholder default.
125   uint32_t hot_startup_method_samples_;
126   uint32_t min_methods_to_save_;
127   uint32_t min_classes_to_save_;
128   uint32_t min_notification_before_wake_;
129   uint32_t max_notification_before_wake_;
130   std::string profile_path_;
131   bool profile_boot_class_path_;
132 };
133 
134 }  // namespace art
135 
136 #endif  // ART_RUNTIME_JIT_PROFILE_SAVER_OPTIONS_H_
137