• 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 <ostream>
17 #include <string>
18 
19 namespace art {
20 
21 struct ProfileSaverOptions {
22  public:
23   static constexpr uint32_t kMinSavePeriodMs = 40 * 1000;  // 40 seconds
24   // Default value for the min save period on first use, indicating that the
25   // period is not configured.
26   static constexpr uint32_t kMinFirstSaveMsNotSet = 0;
27   static constexpr uint32_t kSaveResolvedClassesDelayMs = 5 * 1000;  // 5 seconds
28   // Minimum number of JIT samples during launch to mark a method as hot in the profile.
29   static constexpr uint32_t kHotStartupMethodSamples = 1;
30   static constexpr uint32_t kHotStartupMethodSamplesLowRam = 256;
31   static constexpr uint32_t kMinMethodsToSave = 10;
32   static constexpr uint32_t kMinClassesToSave = 10;
33   static constexpr uint32_t kMinNotificationBeforeWake = 10;
34   static constexpr uint32_t kMaxNotificationBeforeWake = 50;
35   static constexpr uint32_t kHotStartupMethodSamplesNotSet = std::numeric_limits<uint32_t>::max();
36 
ProfileSaverOptionsProfileSaverOptions37   ProfileSaverOptions() :
38     enabled_(false),
39     min_save_period_ms_(kMinSavePeriodMs),
40     min_first_save_ms_(kMinFirstSaveMsNotSet),
41     save_resolved_classes_delay_ms_(kSaveResolvedClassesDelayMs),
42     hot_startup_method_samples_(kHotStartupMethodSamplesNotSet),
43     min_methods_to_save_(kMinMethodsToSave),
44     min_classes_to_save_(kMinClassesToSave),
45     min_notification_before_wake_(kMinNotificationBeforeWake),
46     max_notification_before_wake_(kMaxNotificationBeforeWake),
47     profile_path_(""),
48     profile_boot_class_path_(false),
49     profile_aot_code_(false),
50     wait_for_jit_notifications_to_save_(true) {}
51 
52   ProfileSaverOptions(
53       bool enabled,
54       uint32_t min_save_period_ms,
55       uint32_t min_first_save_ms,
56       uint32_t save_resolved_classes_delay_ms,
57       uint32_t hot_startup_method_samples,
58       uint32_t min_methods_to_save,
59       uint32_t min_classes_to_save,
60       uint32_t min_notification_before_wake,
61       uint32_t max_notification_before_wake,
62       const std::string& profile_path,
63       bool profile_boot_class_path,
64       bool profile_aot_code = false,
65       bool wait_for_jit_notifications_to_save = true)
enabled_ProfileSaverOptions66   : enabled_(enabled),
67     min_save_period_ms_(min_save_period_ms),
68     min_first_save_ms_(min_first_save_ms),
69     save_resolved_classes_delay_ms_(save_resolved_classes_delay_ms),
70     hot_startup_method_samples_(hot_startup_method_samples),
71     min_methods_to_save_(min_methods_to_save),
72     min_classes_to_save_(min_classes_to_save),
73     min_notification_before_wake_(min_notification_before_wake),
74     max_notification_before_wake_(max_notification_before_wake),
75     profile_path_(profile_path),
76     profile_boot_class_path_(profile_boot_class_path),
77     profile_aot_code_(profile_aot_code),
78     wait_for_jit_notifications_to_save_(wait_for_jit_notifications_to_save) {}
79 
IsEnabledProfileSaverOptions80   bool IsEnabled() const {
81     return enabled_;
82   }
SetEnabledProfileSaverOptions83   void SetEnabled(bool enabled) {
84     enabled_ = enabled;
85   }
86 
GetMinSavePeriodMsProfileSaverOptions87   uint32_t GetMinSavePeriodMs() const {
88     return min_save_period_ms_;
89   }
GetMinFirstSaveMsProfileSaverOptions90   uint32_t GetMinFirstSaveMs() const {
91     return min_first_save_ms_;
92   }
GetSaveResolvedClassesDelayMsProfileSaverOptions93   uint32_t GetSaveResolvedClassesDelayMs() const {
94     return save_resolved_classes_delay_ms_;
95   }
GetHotStartupMethodSamplesProfileSaverOptions96   uint32_t GetHotStartupMethodSamples(bool is_low_ram) const {
97     uint32_t ret = hot_startup_method_samples_;
98     if (ret == kHotStartupMethodSamplesNotSet) {
99       ret = is_low_ram ? kHotStartupMethodSamplesLowRam : kHotStartupMethodSamples;
100     }
101     return ret;
102   }
GetMinMethodsToSaveProfileSaverOptions103   uint32_t GetMinMethodsToSave() const {
104     return min_methods_to_save_;
105   }
GetMinClassesToSaveProfileSaverOptions106   uint32_t GetMinClassesToSave() const {
107     return min_classes_to_save_;
108   }
GetMinNotificationBeforeWakeProfileSaverOptions109   uint32_t GetMinNotificationBeforeWake() const {
110     return min_notification_before_wake_;
111   }
GetMaxNotificationBeforeWakeProfileSaverOptions112   uint32_t GetMaxNotificationBeforeWake() const {
113     return max_notification_before_wake_;
114   }
GetProfilePathProfileSaverOptions115   std::string GetProfilePath() const {
116     return profile_path_;
117   }
GetProfileBootClassPathProfileSaverOptions118   bool GetProfileBootClassPath() const {
119     return profile_boot_class_path_;
120   }
GetProfileAOTCodeProfileSaverOptions121   bool GetProfileAOTCode() const {
122     return profile_aot_code_;
123   }
GetWaitForJitNotificationsToSaveProfileSaverOptions124   bool GetWaitForJitNotificationsToSave() const {
125     return wait_for_jit_notifications_to_save_;
126   }
SetWaitForJitNotificationsToSaveProfileSaverOptions127   void SetWaitForJitNotificationsToSave(bool value) {
128     wait_for_jit_notifications_to_save_ = value;
129   }
130 
131   friend std::ostream & operator<<(std::ostream &os, const ProfileSaverOptions& pso) {
132     os << "enabled_" << pso.enabled_
133         << ", min_save_period_ms_" << pso.min_save_period_ms_
134         << ", min_first_save_ms_" << pso.min_first_save_ms_
135         << ", save_resolved_classes_delay_ms_" << pso.save_resolved_classes_delay_ms_
136         << ", hot_startup_method_samples_" << pso.hot_startup_method_samples_
137         << ", min_methods_to_save_" << pso.min_methods_to_save_
138         << ", min_classes_to_save_" << pso.min_classes_to_save_
139         << ", min_notification_before_wake_" << pso.min_notification_before_wake_
140         << ", max_notification_before_wake_" << pso.max_notification_before_wake_
141         << ", profile_boot_class_path_" << pso.profile_boot_class_path_
142         << ", profile_aot_code_" << pso.profile_aot_code_
143         << ", wait_for_jit_notifications_to_save_" << pso.wait_for_jit_notifications_to_save_;
144     return os;
145   }
146 
147   bool enabled_;
148   uint32_t min_save_period_ms_;
149   uint32_t min_first_save_ms_;
150   uint32_t save_resolved_classes_delay_ms_;
151   // Do not access hot_startup_method_samples_ directly for reading since it may be set to the
152   // placeholder default.
153   uint32_t hot_startup_method_samples_;
154   uint32_t min_methods_to_save_;
155   uint32_t min_classes_to_save_;
156   uint32_t min_notification_before_wake_;
157   uint32_t max_notification_before_wake_;
158   std::string profile_path_;
159   bool profile_boot_class_path_;
160   bool profile_aot_code_;
161   bool wait_for_jit_notifications_to_save_;
162 };
163 
164 }  // namespace art
165 
166 #endif  // ART_RUNTIME_JIT_PROFILE_SAVER_OPTIONS_H_
167