blob: 0b6300330f0e986dec46df0792aa3abb341df79c [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
27 kProfilerMethodAndDexPC, // Method with Dex PC
28};
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;
Calin Juravlec1b643c2014-05-30 23:44:11 +010041
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 Jina93b0bb2014-06-09 16:19:15 -070050 top_k_change_threshold_(kDefaultChangeInTopKThreshold),
51 profile_type_(kDefaultProfileData) {}
Calin Juravlec1b643c2014-05-30 23:44:11 +010052
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 Jina93b0bb2014-06-09 16:19:15 -070060 double top_k_change_threshold,
61 ProfileDataType profile_type):
Calin Juravlec1b643c2014-05-30 23:44:11 +010062 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 Jina93b0bb2014-06-09 16:19:15 -070069 top_k_change_threshold_(top_k_change_threshold),
70 profile_type_(profile_type) {}
Calin Juravlec1b643c2014-05-30 23:44:11 +010071
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 Jina93b0bb2014-06-09 16:19:15 -0700104 ProfileDataType GetProfileType() const {
105 return profile_type_;
106 }
107
Calin Juravlec1b643c2014-05-30 23:44:11 +0100108 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 Jina93b0bb2014-06-09 16:19:15 -0700117 << ", top_k_change_threshold=" << po.top_k_change_threshold_
118 << ", profile_type=" << po.profile_type_;
Calin Juravlec1b643c2014-05-30 23:44:11 +0100119 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 Jina93b0bb2014-06-09 16:19:15 -0700140 // The type of profile data dumped to the disk.
141 ProfileDataType profile_type_;
Calin Juravlec1b643c2014-05-30 23:44:11 +0100142};
143
144} // namespace art
145
146
147#endif // ART_RUNTIME_PROFILER_OPTIONS_H_