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 <cstdint>
17 #include <ostream>
18 #include <string>
19 
20 namespace art HIDDEN {
21 
22 struct ProfileSaverOptions {
23  public:
24   static constexpr uint32_t kMinSavePeriodMs = 40 * 1000;  // 40 seconds
25   // Default value for the min save period on first use, indicating that the
26   // period is not configured.
27   static constexpr uint32_t kMinFirstSaveMsNotSet = 0;
28   static constexpr uint32_t kSaveResolvedClassesDelayMs = 5 * 1000;  // 5 seconds
29   static constexpr uint32_t kMinMethodsToSave = 10;
30   static constexpr uint32_t kMinClassesToSave = 10;
31   static constexpr uint32_t kMinNotificationBeforeWake = 10;
32   static constexpr uint32_t kMaxNotificationBeforeWake = 50;
33   static constexpr uint16_t kInlineCacheThreshold = 4000;
34 
ProfileSaverOptionsProfileSaverOptions35   ProfileSaverOptions() :
36     enabled_(false),
37     min_save_period_ms_(kMinSavePeriodMs),
38     min_first_save_ms_(kMinFirstSaveMsNotSet),
39     save_resolved_classes_delay_ms_(kSaveResolvedClassesDelayMs),
40     min_methods_to_save_(kMinMethodsToSave),
41     min_classes_to_save_(kMinClassesToSave),
42     min_notification_before_wake_(kMinNotificationBeforeWake),
43     max_notification_before_wake_(kMaxNotificationBeforeWake),
44     inline_cache_threshold_(kInlineCacheThreshold),
45     profile_path_(""),
46     profile_boot_class_path_(false),
47     profile_aot_code_(false),
48     wait_for_jit_notifications_to_save_(true) {}
49 
50   ProfileSaverOptions(
51       bool enabled,
52       uint32_t min_save_period_ms,
53       uint32_t min_first_save_ms,
54       uint32_t save_resolved_classes_delay_ms,
55       uint32_t min_methods_to_save,
56       uint32_t min_classes_to_save,
57       uint32_t min_notification_before_wake,
58       uint32_t max_notification_before_wake,
59       uint16_t inline_cache_threshold,
60       const std::string& profile_path,
61       bool profile_boot_class_path,
62       bool profile_aot_code = false,
63       bool wait_for_jit_notifications_to_save = true)
enabled_ProfileSaverOptions64   : enabled_(enabled),
65     min_save_period_ms_(min_save_period_ms),
66     min_first_save_ms_(min_first_save_ms),
67     save_resolved_classes_delay_ms_(save_resolved_classes_delay_ms),
68     min_methods_to_save_(min_methods_to_save),
69     min_classes_to_save_(min_classes_to_save),
70     min_notification_before_wake_(min_notification_before_wake),
71     max_notification_before_wake_(max_notification_before_wake),
72     inline_cache_threshold_(inline_cache_threshold),
73     profile_path_(profile_path),
74     profile_boot_class_path_(profile_boot_class_path),
75     profile_aot_code_(profile_aot_code),
76     wait_for_jit_notifications_to_save_(wait_for_jit_notifications_to_save) {}
77 
IsEnabledProfileSaverOptions78   bool IsEnabled() const {
79     return enabled_;
80   }
SetEnabledProfileSaverOptions81   void SetEnabled(bool enabled) {
82     enabled_ = enabled;
83   }
84 
GetMinSavePeriodMsProfileSaverOptions85   uint32_t GetMinSavePeriodMs() const {
86     return min_save_period_ms_;
87   }
GetMinFirstSaveMsProfileSaverOptions88   uint32_t GetMinFirstSaveMs() const {
89     return min_first_save_ms_;
90   }
GetSaveResolvedClassesDelayMsProfileSaverOptions91   uint32_t GetSaveResolvedClassesDelayMs() const {
92     return save_resolved_classes_delay_ms_;
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   }
GetInlineCacheThresholdProfileSaverOptions106   uint16_t GetInlineCacheThreshold() const {
107     return inline_cache_threshold_;
108   }
GetProfilePathProfileSaverOptions109   std::string GetProfilePath() const {
110     return profile_path_;
111   }
GetProfileBootClassPathProfileSaverOptions112   bool GetProfileBootClassPath() const {
113     return profile_boot_class_path_;
114   }
GetProfileAOTCodeProfileSaverOptions115   bool GetProfileAOTCode() const {
116     return profile_aot_code_;
117   }
GetWaitForJitNotificationsToSaveProfileSaverOptions118   bool GetWaitForJitNotificationsToSave() const {
119     return wait_for_jit_notifications_to_save_;
120   }
SetWaitForJitNotificationsToSaveProfileSaverOptions121   void SetWaitForJitNotificationsToSave(bool value) {
122     wait_for_jit_notifications_to_save_ = value;
123   }
124 
125   friend std::ostream & operator<<(std::ostream &os, const ProfileSaverOptions& pso) {
126     os << "enabled_" << pso.enabled_
127         << ", min_save_period_ms_" << pso.min_save_period_ms_
128         << ", min_first_save_ms_" << pso.min_first_save_ms_
129         << ", save_resolved_classes_delay_ms_" << pso.save_resolved_classes_delay_ms_
130         << ", min_methods_to_save_" << pso.min_methods_to_save_
131         << ", min_classes_to_save_" << pso.min_classes_to_save_
132         << ", min_notification_before_wake_" << pso.min_notification_before_wake_
133         << ", max_notification_before_wake_" << pso.max_notification_before_wake_
134         << ", inline_cache_threshold_" << pso.inline_cache_threshold_
135         << ", profile_boot_class_path_" << pso.profile_boot_class_path_
136         << ", profile_aot_code_" << pso.profile_aot_code_
137         << ", wait_for_jit_notifications_to_save_" << pso.wait_for_jit_notifications_to_save_;
138     return os;
139   }
140 
141   bool enabled_;
142   uint32_t min_save_period_ms_;
143   uint32_t min_first_save_ms_;
144   uint32_t save_resolved_classes_delay_ms_;
145   uint32_t min_methods_to_save_;
146   uint32_t min_classes_to_save_;
147   uint32_t min_notification_before_wake_;
148   uint32_t max_notification_before_wake_;
149   uint16_t inline_cache_threshold_;
150   std::string profile_path_;
151   bool profile_boot_class_path_;
152   bool profile_aot_code_;
153   bool wait_for_jit_notifications_to_save_;
154 };
155 
156 }  // namespace art
157 
158 #endif  // ART_RUNTIME_JIT_PROFILE_SAVER_OPTIONS_H_
159