summaryrefslogtreecommitdiffstats
path: root/runtime/profiler_options.h
blob: 1db2f0508c89ae4af96ed89b2a612b9f55ecac03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ART_RUNTIME_PROFILER_OPTIONS_H_
#define ART_RUNTIME_PROFILER_OPTIONS_H_

#include <string>
#include <ostream>

namespace art {

enum ProfileDataType {
  kProfilerMethod,          // Method only
  kProfilerBoundedStack,    // Methods with Dex PC on top of the stack
};
std::ostream& operator<<(std::ostream& os, const ProfileDataType& rhs);

class ProfilerOptions {
 public:
  static constexpr bool kDefaultEnabled = false;
  static constexpr uint32_t kDefaultPeriodS = 10;
  static constexpr uint32_t kDefaultDurationS = 20;
  static constexpr uint32_t kDefaultIntervalUs = 500;
  static constexpr double kDefaultBackoffCoefficient = 2.0;
  static constexpr bool kDefaultStartImmediately = false;
  static constexpr double kDefaultTopKThreshold = 90.0;
  static constexpr double kDefaultChangeInTopKThreshold = 10.0;
  static constexpr ProfileDataType kDefaultProfileData = kProfilerMethod;
  static constexpr uint32_t kDefaultMaxStackDepth = 3;

  ProfilerOptions() :
    enabled_(kDefaultEnabled),
    period_s_(kDefaultPeriodS),
    duration_s_(kDefaultDurationS),
    interval_us_(kDefaultIntervalUs),
    backoff_coefficient_(kDefaultBackoffCoefficient),
    start_immediately_(kDefaultStartImmediately),
    top_k_threshold_(kDefaultTopKThreshold),
    top_k_change_threshold_(kDefaultChangeInTopKThreshold),
    profile_type_(kDefaultProfileData),
    max_stack_depth_(kDefaultMaxStackDepth) {}

  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):
    enabled_(enabled),
    period_s_(period_s),
    duration_s_(duration_s),
    interval_us_(interval_us),
    backoff_coefficient_(backoff_coefficient),
    start_immediately_(start_immediately),
    top_k_threshold_(top_k_threshold),
    top_k_change_threshold_(top_k_change_threshold),
    profile_type_(profile_type),
    max_stack_depth_(max_stack_depth) {}

  bool IsEnabled() const {
    return enabled_;
  }

  uint32_t GetPeriodS() const {
    return period_s_;
  }

  uint32_t GetDurationS() const {
    return duration_s_;
  }

  uint32_t GetIntervalUs() const {
    return interval_us_;
  }

  double GetBackoffCoefficient() const {
    return backoff_coefficient_;
  }

  bool GetStartImmediately() const {
    return start_immediately_;
  }

  double GetTopKThreshold() const {
    return top_k_threshold_;
  }

  double GetTopKChangeThreshold() const {
    return top_k_change_threshold_;
  }

  ProfileDataType GetProfileType() const {
    return profile_type_;
  }

  uint32_t GetMaxStackDepth() const {
    return max_stack_depth_;
  }

 private:
  friend std::ostream & operator<<(std::ostream &os, const ProfilerOptions& po) {
    os << "enabled=" << po.enabled_
       << ", period_s=" << po.period_s_
       << ", duration_s=" << po.duration_s_
       << ", interval_us=" << po.interval_us_
       << ", backoff_coefficient=" << po.backoff_coefficient_
       << ", start_immediately=" << po.start_immediately_
       << ", top_k_threshold=" << po.top_k_threshold_
       << ", top_k_change_threshold=" << po.top_k_change_threshold_
       << ", profile_type=" << po.profile_type_
       << ", max_stack_depth=" << po.max_stack_depth_;
    return os;
  }

  friend class ParsedOptions;

  // Whether or not the applications should be profiled.
  bool enabled_;
  // Generate profile every n seconds.
  uint32_t period_s_;
  // Run profile for n seconds.
  uint32_t duration_s_;
  // Microseconds between samples.
  uint32_t interval_us_;
  // Coefficient to exponential backoff.
  double backoff_coefficient_;
  // Whether the profile should start upon app startup or be delayed by some random offset.
  bool start_immediately_;
  // Top K% of samples that are considered relevant when deciding if the app should be recompiled.
  double top_k_threshold_;
  // How much the top K% samples needs to change in order for the app to be recompiled.
  double top_k_change_threshold_;
  // The type of profile data dumped to the disk.
  ProfileDataType profile_type_;
  // The max depth of the stack collected by the profiler
  uint32_t max_stack_depth_;
};

}  // namespace art


#endif  // ART_RUNTIME_PROFILER_OPTIONS_H_