• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 std::ostream& operator<<(std::ostream& os, const ProfileDataType& rhs);
30 
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;
41   static constexpr ProfileDataType kDefaultProfileData = kProfilerMethod;
42   static constexpr uint32_t kDefaultMaxStackDepth = 3;
43 
ProfilerOptions()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),
52     top_k_change_threshold_(kDefaultChangeInTopKThreshold),
53     profile_type_(kDefaultProfileData),
54     max_stack_depth_(kDefaultMaxStackDepth) {}
55 
ProfilerOptions(bool enabled,uint32_t period_s,uint32_t duration_s,uint32_t interval_us,double backoff_coefficient,bool start_immediately,double top_k_threshold,double top_k_change_threshold,ProfileDataType profile_type,uint32_t max_stack_depth)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,
63                  double top_k_change_threshold,
64                  ProfileDataType profile_type,
65                  uint32_t max_stack_depth):
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),
73     top_k_change_threshold_(top_k_change_threshold),
74     profile_type_(profile_type),
75     max_stack_depth_(max_stack_depth) {}
76 
IsEnabled()77   bool IsEnabled() const {
78     return enabled_;
79   }
80 
GetPeriodS()81   uint32_t GetPeriodS() const {
82     return period_s_;
83   }
84 
GetDurationS()85   uint32_t GetDurationS() const {
86     return duration_s_;
87   }
88 
GetIntervalUs()89   uint32_t GetIntervalUs() const {
90     return interval_us_;
91   }
92 
GetBackoffCoefficient()93   double GetBackoffCoefficient() const {
94     return backoff_coefficient_;
95   }
96 
GetStartImmediately()97   bool GetStartImmediately() const {
98     return start_immediately_;
99   }
100 
GetTopKThreshold()101   double GetTopKThreshold() const {
102     return top_k_threshold_;
103   }
104 
GetTopKChangeThreshold()105   double GetTopKChangeThreshold() const {
106     return top_k_change_threshold_;
107   }
108 
GetProfileType()109   ProfileDataType GetProfileType() const {
110     return profile_type_;
111   }
112 
GetMaxStackDepth()113   uint32_t GetMaxStackDepth() const {
114     return max_stack_depth_;
115   }
116 
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_
126        << ", top_k_change_threshold=" << po.top_k_change_threshold_
127        << ", profile_type=" << po.profile_type_
128        << ", max_stack_depth=" << po.max_stack_depth_;
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_;
150   // The type of profile data dumped to the disk.
151   ProfileDataType profile_type_;
152   // The max depth of the stack collected by the profiler
153   uint32_t max_stack_depth_;
154 };
155 
156 }  // namespace art
157 
158 
159 #endif  // ART_RUNTIME_PROFILER_OPTIONS_H_
160