blob: e3ef69739b2e29c3b2adc0e755a1dbf3b4e406c6 [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};
29
Calin Juravlec1b643c2014-05-30 23:44:11 +010030class 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 Jina93b0bb2014-06-09 16:19:15 -070040 static constexpr ProfileDataType kDefaultProfileData = kProfilerMethod;
Wei Jin445220d2014-06-20 15:56:53 -070041 static constexpr uint32_t kDefaultMaxStackDepth = 3;
Calin Juravlec1b643c2014-05-30 23:44:11 +010042
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),
Wei Jina93b0bb2014-06-09 16:19:15 -070051 top_k_change_threshold_(kDefaultChangeInTopKThreshold),
Wei Jin445220d2014-06-20 15:56:53 -070052 profile_type_(kDefaultProfileData),
53 max_stack_depth_(kDefaultMaxStackDepth) {}
Calin Juravlec1b643c2014-05-30 23:44:11 +010054
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,
Wei Jina93b0bb2014-06-09 16:19:15 -070062 double top_k_change_threshold,
Wei Jin445220d2014-06-20 15:56:53 -070063 ProfileDataType profile_type,
64 uint32_t max_stack_depth):
Calin Juravlec1b643c2014-05-30 23:44:11 +010065 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),
Wei Jina93b0bb2014-06-09 16:19:15 -070072 top_k_change_threshold_(top_k_change_threshold),
Wei Jin445220d2014-06-20 15:56:53 -070073 profile_type_(profile_type),
74 max_stack_depth_(max_stack_depth) {}
Calin Juravlec1b643c2014-05-30 23:44:11 +010075
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
Wei Jina93b0bb2014-06-09 16:19:15 -0700108 ProfileDataType GetProfileType() const {
109 return profile_type_;
110 }
111
Wei Jin445220d2014-06-20 15:56:53 -0700112 uint32_t GetMaxStackDepth() const {
113 return max_stack_depth_;
114 }
115
Calin Juravlec1b643c2014-05-30 23:44:11 +0100116 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_
Wei Jina93b0bb2014-06-09 16:19:15 -0700125 << ", top_k_change_threshold=" << po.top_k_change_threshold_
Wei Jin445220d2014-06-20 15:56:53 -0700126 << ", profile_type=" << po.profile_type_
127 << ", max_stack_depth=" << po.max_stack_depth_;
Calin Juravlec1b643c2014-05-30 23:44:11 +0100128 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_;
Wei Jina93b0bb2014-06-09 16:19:15 -0700149 // The type of profile data dumped to the disk.
150 ProfileDataType profile_type_;
Wei Jin445220d2014-06-20 15:56:53 -0700151 // The max depth of the stack collected by the profiler
152 uint32_t max_stack_depth_;
Calin Juravlec1b643c2014-05-30 23:44:11 +0100153};
154
155} // namespace art
156
157
158#endif // ART_RUNTIME_PROFILER_OPTIONS_H_