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 include a method into the profile.
26   static constexpr uint32_t kStartupMethodSamples = 1;
27   static constexpr uint32_t kMinMethodsToSave = 10;
28   static constexpr uint32_t kMinClassesToSave = 10;
29   static constexpr uint32_t kMinNotificationBeforeWake = 10;
30   static constexpr uint32_t kMaxNotificationBeforeWake = 50;
31 
ProfileSaverOptionsProfileSaverOptions32   ProfileSaverOptions() :
33     enabled_(false),
34     min_save_period_ms_(kMinSavePeriodMs),
35     save_resolved_classes_delay_ms_(kSaveResolvedClassesDelayMs),
36     startup_method_samples_(kStartupMethodSamples),
37     min_methods_to_save_(kMinMethodsToSave),
38     min_classes_to_save_(kMinClassesToSave),
39     min_notification_before_wake_(kMinNotificationBeforeWake),
40     max_notification_before_wake_(kMaxNotificationBeforeWake),
41     profile_path_("") {}
42 
ProfileSaverOptionsProfileSaverOptions43   ProfileSaverOptions(
44       bool enabled,
45       uint32_t min_save_period_ms,
46       uint32_t save_resolved_classes_delay_ms,
47       uint32_t startup_method_samples,
48       uint32_t min_methods_to_save,
49       uint32_t min_classes_to_save,
50       uint32_t min_notification_before_wake,
51       uint32_t max_notification_before_wake,
52       const std::string& profile_path):
53     enabled_(enabled),
54     min_save_period_ms_(min_save_period_ms),
55     save_resolved_classes_delay_ms_(save_resolved_classes_delay_ms),
56     startup_method_samples_(startup_method_samples),
57     min_methods_to_save_(min_methods_to_save),
58     min_classes_to_save_(min_classes_to_save),
59     min_notification_before_wake_(min_notification_before_wake),
60     max_notification_before_wake_(max_notification_before_wake),
61     profile_path_(profile_path) {}
62 
IsEnabledProfileSaverOptions63   bool IsEnabled() const {
64     return enabled_;
65   }
SetEnabledProfileSaverOptions66   void SetEnabled(bool enabled) {
67     enabled_ = enabled;
68   }
69 
GetMinSavePeriodMsProfileSaverOptions70   uint32_t GetMinSavePeriodMs() const {
71     return min_save_period_ms_;
72   }
GetSaveResolvedClassesDelayMsProfileSaverOptions73   uint32_t GetSaveResolvedClassesDelayMs() const {
74     return save_resolved_classes_delay_ms_;
75   }
GetStartupMethodSamplesProfileSaverOptions76   uint32_t GetStartupMethodSamples() const {
77     return startup_method_samples_;
78   }
GetMinMethodsToSaveProfileSaverOptions79   uint32_t GetMinMethodsToSave() const {
80     return min_methods_to_save_;
81   }
GetMinClassesToSaveProfileSaverOptions82   uint32_t GetMinClassesToSave() const {
83     return min_classes_to_save_;
84   }
GetMinNotificationBeforeWakeProfileSaverOptions85   uint32_t GetMinNotificationBeforeWake() const {
86     return min_notification_before_wake_;
87   }
GetMaxNotificationBeforeWakeProfileSaverOptions88   uint32_t GetMaxNotificationBeforeWake() const {
89     return max_notification_before_wake_;
90   }
GetProfilePathProfileSaverOptions91   std::string GetProfilePath() const {
92     return profile_path_;
93   }
94 
95   friend std::ostream & operator<<(std::ostream &os, const ProfileSaverOptions& pso) {
96     os << "enabled_" << pso.enabled_
97         << ", min_save_period_ms_" << pso.min_save_period_ms_
98         << ", save_resolved_classes_delay_ms_" << pso.save_resolved_classes_delay_ms_
99         << ", startup_method_samples_" << pso.startup_method_samples_
100         << ", min_methods_to_save_" << pso.min_methods_to_save_
101         << ", min_classes_to_save_" << pso.min_classes_to_save_
102         << ", min_notification_before_wake_" << pso.min_notification_before_wake_
103         << ", max_notification_before_wake_" << pso.max_notification_before_wake_;
104     return os;
105   }
106 
107   bool enabled_;
108   uint32_t min_save_period_ms_;
109   uint32_t save_resolved_classes_delay_ms_;
110   uint32_t startup_method_samples_;
111   uint32_t min_methods_to_save_;
112   uint32_t min_classes_to_save_;
113   uint32_t min_notification_before_wake_;
114   uint32_t max_notification_before_wake_;
115   std::string profile_path_;
116 };
117 
118 }  // namespace art
119 
120 #endif  // ART_RUNTIME_JIT_PROFILE_SAVER_OPTIONS_H_
121