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