blob: 1db2f0508c89ae4af96ed89b2a612b9f55ecac03 [file] [log] [blame]
Calin Juravlec1b643c2014-05-30 23:44:11 +01001/*
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
23namespace art {
24
Wei Jina93b0bb2014-06-09 16:19:15 -070025enum ProfileDataType {
26 kProfilerMethod, // Method only
Wei Jin445220d2014-06-20 15:56:53 -070027 kProfilerBoundedStack, // Methods with Dex PC on top of the stack
Wei Jina93b0bb2014-06-09 16:19:15 -070028};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070029std::ostream& operator<<(std::ostream& os, const ProfileDataType& rhs);
Wei Jina93b0bb2014-06-09 16:19:15 -070030
Calin Juravlec1b643c2014-05-30 23:44:11 +010031class 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 Jina93b0bb2014-06-09 16:19:15 -070041 static constexpr ProfileDataType kDefaultProfileData = kProfilerMethod;
Wei Jin445220d2014-06-20 15:56:53 -070042 static constexpr uint32_t kDefaultMaxStackDepth = 3;
Calin Juravlec1b643c2014-05-30 23:44:11 +010043
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 Jina93b0bb2014-06-09 16:19:15 -070052 top_k_change_threshold_(kDefaultChangeInTopKThreshold),
Wei Jin445220d2014-06-20 15:56:53 -070053 profile_type_(kDefaultProfileData),
54 max_stack_depth_(kDefaultMaxStackDepth) {}
Calin Juravlec1b643c2014-05-30 23:44:11 +010055
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 Jina93b0bb2014-06-09 16:19:15 -070063 double top_k_change_threshold,
Wei Jin445220d2014-06-20 15:56:53 -070064 ProfileDataType profile_type,
65 uint32_t max_stack_depth):
Calin Juravlec1b643c2014-05-30 23:44:11 +010066 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 Jina93b0bb2014-06-09 16:19:15 -070073 top_k_change_threshold_(top_k_change_threshold),
Wei Jin445220d2014-06-20 15:56:53 -070074 profile_type_(profile_type),
75 max_stack_depth_(max_stack_depth) {}
Calin Juravlec1b643c2014-05-30 23:44:11 +010076
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 Jina93b0bb2014-06-09 16:19:15 -0700109 ProfileDataType GetProfileType() const {
110 return profile_type_;
111 }
112
Wei Jin445220d2014-06-20 15:56:53 -0700113 uint32_t GetMaxStackDepth() const {
114 return max_stack_depth_;
115 }
116
Calin Juravlec1b643c2014-05-30 23:44:11 +0100117 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 Jina93b0bb2014-06-09 16:19:15 -0700126 << ", top_k_change_threshold=" << po.top_k_change_threshold_
Wei Jin445220d2014-06-20 15:56:53 -0700127 << ", profile_type=" << po.profile_type_
128 << ", max_stack_depth=" << po.max_stack_depth_;
Calin Juravlec1b643c2014-05-30 23:44:11 +0100129 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 Jina93b0bb2014-06-09 16:19:15 -0700150 // The type of profile data dumped to the disk.
151 ProfileDataType profile_type_;
Wei Jin445220d2014-06-20 15:56:53 -0700152 // The max depth of the stack collected by the profiler
153 uint32_t max_stack_depth_;
Calin Juravlec1b643c2014-05-30 23:44:11 +0100154};
155
156} // namespace art
157
158
159#endif // ART_RUNTIME_PROFILER_OPTIONS_H_