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   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     profile_aot_code_(false),
46     wait_for_jit_notifications_to_save_(true) {}
47 
48   ProfileSaverOptions(
49       bool enabled,
50       uint32_t min_save_period_ms,
51       uint32_t save_resolved_classes_delay_ms,
52       uint32_t hot_startup_method_samples,
53       uint32_t min_methods_to_save,
54       uint32_t min_classes_to_save,
55       uint32_t min_notification_before_wake,
56       uint32_t max_notification_before_wake,
57       const std::string& profile_path,
58       bool profile_boot_class_path,
59       bool profile_aot_code = false,
60       bool wait_for_jit_notifications_to_save = true)
enabled_ProfileSaverOptions61   : enabled_(enabled),
62     min_save_period_ms_(min_save_period_ms),
63     save_resolved_classes_delay_ms_(save_resolved_classes_delay_ms),
64     hot_startup_method_samples_(hot_startup_method_samples),
65     min_methods_to_save_(min_methods_to_save),
66     min_classes_to_save_(min_classes_to_save),
67     min_notification_before_wake_(min_notification_before_wake),
68     max_notification_before_wake_(max_notification_before_wake),
69     profile_path_(profile_path),
70     profile_boot_class_path_(profile_boot_class_path),
71     profile_aot_code_(profile_aot_code),
72     wait_for_jit_notifications_to_save_(wait_for_jit_notifications_to_save) {}
73 
IsEnabledProfileSaverOptions74   bool IsEnabled() const {
75     return enabled_;
76   }
SetEnabledProfileSaverOptions77   void SetEnabled(bool enabled) {
78     enabled_ = enabled;
79   }
80 
GetMinSavePeriodMsProfileSaverOptions81   uint32_t GetMinSavePeriodMs() const {
82     return min_save_period_ms_;
83   }
GetSaveResolvedClassesDelayMsProfileSaverOptions84   uint32_t GetSaveResolvedClassesDelayMs() const {
85     return save_resolved_classes_delay_ms_;
86   }
GetHotStartupMethodSamplesProfileSaverOptions87   uint32_t GetHotStartupMethodSamples(bool is_low_ram) const {
88     uint32_t ret = hot_startup_method_samples_;
89     if (ret == kHotStartupMethodSamplesNotSet) {
90       ret = is_low_ram ? kHotStartupMethodSamplesLowRam : kHotStartupMethodSamples;
91     }
92     return ret;
93   }
GetMinMethodsToSaveProfileSaverOptions94   uint32_t GetMinMethodsToSave() const {
95     return min_methods_to_save_;
96   }
GetMinClassesToSaveProfileSaverOptions97   uint32_t GetMinClassesToSave() const {
98     return min_classes_to_save_;
99   }
GetMinNotificationBeforeWakeProfileSaverOptions100   uint32_t GetMinNotificationBeforeWake() const {
101     return min_notification_before_wake_;
102   }
GetMaxNotificationBeforeWakeProfileSaverOptions103   uint32_t GetMaxNotificationBeforeWake() const {
104     return max_notification_before_wake_;
105   }
GetProfilePathProfileSaverOptions106   std::string GetProfilePath() const {
107     return profile_path_;
108   }
GetProfileBootClassPathProfileSaverOptions109   bool GetProfileBootClassPath() const {
110     return profile_boot_class_path_;
111   }
GetProfileAOTCodeProfileSaverOptions112   bool GetProfileAOTCode() const {
113     return profile_aot_code_;
114   }
GetWaitForJitNotificationsToSaveProfileSaverOptions115   bool GetWaitForJitNotificationsToSave() const {
116     return wait_for_jit_notifications_to_save_;
117   }
SetWaitForJitNotificationsToSaveProfileSaverOptions118   void SetWaitForJitNotificationsToSave(bool value) {
119     wait_for_jit_notifications_to_save_ = value;
120   }
121 
122   friend std::ostream & operator<<(std::ostream &os, const ProfileSaverOptions& pso) {
123     os << "enabled_" << pso.enabled_
124         << ", min_save_period_ms_" << pso.min_save_period_ms_
125         << ", save_resolved_classes_delay_ms_" << pso.save_resolved_classes_delay_ms_
126         << ", hot_startup_method_samples_" << pso.hot_startup_method_samples_
127         << ", min_methods_to_save_" << pso.min_methods_to_save_
128         << ", min_classes_to_save_" << pso.min_classes_to_save_
129         << ", min_notification_before_wake_" << pso.min_notification_before_wake_
130         << ", max_notification_before_wake_" << pso.max_notification_before_wake_
131         << ", profile_boot_class_path_" << pso.profile_boot_class_path_
132         << ", profile_aot_code_" << pso.profile_aot_code_
133         << ", wait_for_jit_notifications_to_save_" << pso.wait_for_jit_notifications_to_save_;
134     return os;
135   }
136 
137   bool enabled_;
138   uint32_t min_save_period_ms_;
139   uint32_t save_resolved_classes_delay_ms_;
140   // Do not access hot_startup_method_samples_ directly for reading since it may be set to the
141   // placeholder default.
142   uint32_t hot_startup_method_samples_;
143   uint32_t min_methods_to_save_;
144   uint32_t min_classes_to_save_;
145   uint32_t min_notification_before_wake_;
146   uint32_t max_notification_before_wake_;
147   std::string profile_path_;
148   bool profile_boot_class_path_;
149   bool profile_aot_code_;
150   bool wait_for_jit_notifications_to_save_;
151 };
152 
153 }  // namespace art
154 
155 #endif  // ART_RUNTIME_JIT_PROFILE_SAVER_OPTIONS_H_
156