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