1 /* 2 * Copyright (C) 2014 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 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ART_RUNTIME_PROFILER_OPTIONS_H_ 18 #define ART_RUNTIME_PROFILER_OPTIONS_H_ 19 20 #include <string> 21 #include <ostream> 22 23 namespace art { 24 25 enum ProfileDataType { 26 kProfilerMethod, // Method only 27 kProfilerBoundedStack, // Methods with Dex PC on top of the stack 28 }; 29 30 class ProfilerOptions { 31 public: 32 static constexpr bool kDefaultEnabled = false; 33 static constexpr uint32_t kDefaultPeriodS = 10; 34 static constexpr uint32_t kDefaultDurationS = 20; 35 static constexpr uint32_t kDefaultIntervalUs = 500; 36 static constexpr double kDefaultBackoffCoefficient = 2.0; 37 static constexpr bool kDefaultStartImmediately = false; 38 static constexpr double kDefaultTopKThreshold = 90.0; 39 static constexpr double kDefaultChangeInTopKThreshold = 10.0; 40 static constexpr ProfileDataType kDefaultProfileData = kProfilerMethod; 41 static constexpr uint32_t kDefaultMaxStackDepth = 3; 42 43 ProfilerOptions() : 44 enabled_(kDefaultEnabled), 45 period_s_(kDefaultPeriodS), 46 duration_s_(kDefaultDurationS), 47 interval_us_(kDefaultIntervalUs), 48 backoff_coefficient_(kDefaultBackoffCoefficient), 49 start_immediately_(kDefaultStartImmediately), 50 top_k_threshold_(kDefaultTopKThreshold), 51 top_k_change_threshold_(kDefaultChangeInTopKThreshold), 52 profile_type_(kDefaultProfileData), 53 max_stack_depth_(kDefaultMaxStackDepth) {} 54 55 ProfilerOptions(bool enabled, 56 uint32_t period_s, 57 uint32_t duration_s, 58 uint32_t interval_us, 59 double backoff_coefficient, 60 bool start_immediately, 61 double top_k_threshold, 62 double top_k_change_threshold, 63 ProfileDataType profile_type, 64 uint32_t max_stack_depth): 65 enabled_(enabled), 66 period_s_(period_s), 67 duration_s_(duration_s), 68 interval_us_(interval_us), 69 backoff_coefficient_(backoff_coefficient), 70 start_immediately_(start_immediately), 71 top_k_threshold_(top_k_threshold), 72 top_k_change_threshold_(top_k_change_threshold), 73 profile_type_(profile_type), 74 max_stack_depth_(max_stack_depth) {} 75 76 bool IsEnabled() const { 77 return enabled_; 78 } 79 80 uint32_t GetPeriodS() const { 81 return period_s_; 82 } 83 84 uint32_t GetDurationS() const { 85 return duration_s_; 86 } 87 88 uint32_t GetIntervalUs() const { 89 return interval_us_; 90 } 91 92 double GetBackoffCoefficient() const { 93 return backoff_coefficient_; 94 } 95 96 bool GetStartImmediately() const { 97 return start_immediately_; 98 } 99 100 double GetTopKThreshold() const { 101 return top_k_threshold_; 102 } 103 104 double GetTopKChangeThreshold() const { 105 return top_k_change_threshold_; 106 } 107 108 ProfileDataType GetProfileType() const { 109 return profile_type_; 110 } 111 112 uint32_t GetMaxStackDepth() const { 113 return max_stack_depth_; 114 } 115 116 private: 117 friend std::ostream & operator<<(std::ostream &os, const ProfilerOptions& po) { 118 os << "enabled=" << po.enabled_ 119 << ", period_s=" << po.period_s_ 120 << ", duration_s=" << po.duration_s_ 121 << ", interval_us=" << po.interval_us_ 122 << ", backoff_coefficient=" << po.backoff_coefficient_ 123 << ", start_immediately=" << po.start_immediately_ 124 << ", top_k_threshold=" << po.top_k_threshold_ 125 << ", top_k_change_threshold=" << po.top_k_change_threshold_ 126 << ", profile_type=" << po.profile_type_ 127 << ", max_stack_depth=" << po.max_stack_depth_; 128 return os; 129 } 130 131 friend class ParsedOptions; 132 133 // Whether or not the applications should be profiled. 134 bool enabled_; 135 // Generate profile every n seconds. 136 uint32_t period_s_; 137 // Run profile for n seconds. 138 uint32_t duration_s_; 139 // Microseconds between samples. 140 uint32_t interval_us_; 141 // Coefficient to exponential backoff. 142 double backoff_coefficient_; 143 // Whether the profile should start upon app startup or be delayed by some random offset. 144 bool start_immediately_; 145 // Top K% of samples that are considered relevant when deciding if the app should be recompiled. 146 double top_k_threshold_; 147 // How much the top K% samples needs to change in order for the app to be recompiled. 148 double top_k_change_threshold_; 149 // The type of profile data dumped to the disk. 150 ProfileDataType profile_type_; 151 // The max depth of the stack collected by the profiler 152 uint32_t max_stack_depth_; 153 }; 154 155 } // namespace art 156 157 158 #endif // ART_RUNTIME_PROFILER_OPTIONS_H_ 159