-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy patharguments.h
More file actions
255 lines (221 loc) · 6.92 KB
/
arguments.h
File metadata and controls
255 lines (221 loc) · 6.92 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
* Copyright 2017 Andrei Pangin
* Copyright 2026, Datadog, Inc.
*
* 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 _ARGUMENTS_H
#define _ARGUMENTS_H
#include <cstring>
#include <stddef.h>
#include <string>
#include <vector>
const long DEFAULT_CPU_INTERVAL = 10 * 1000 * 1000; // 10 ms
const long DEFAULT_WALL_INTERVAL = 50 * 1000 * 1000; // 50 ms
const long DEFAULT_ALLOC_INTERVAL = 524287; // 512 KiB
const int DEFAULT_WALL_THREADS_PER_TICK = 16;
const int DEFAULT_JSTACKDEPTH = 2048;
const char *const EVENT_NOOP = "noop";
const char *const EVENT_CPU = "cpu";
const char *const EVENT_ALLOC = "alloc";
const char *const EVENT_WALL = "wall";
const char *const EVENT_ITIMER = "itimer";
const char *const EVENT_CTIMER = "ctimer";
const char *const EVENT_NATIVEMEM = "nativemem";
enum Action {
ACTION_NONE,
ACTION_START,
ACTION_RESUME,
ACTION_STOP,
ACTION_CHECK,
ACTION_STATUS,
ACTION_LIST,
ACTION_VERSION
};
enum Ring {
RING_KERNEL = 1,
RING_USER = 1 << 1,
RING_ANY = RING_KERNEL | RING_USER,
};
enum Style {
STYLE_SIMPLE = 1,
STYLE_DOTTED = 2,
STYLE_SIGNATURES = 4,
STYLE_ANNOTATE = 8,
STYLE_LIB_NAMES = 16
};
enum CStack {
CSTACK_DEFAULT, // use perf_event_open stack if available or Frame Pointer links otherwise
CSTACK_NO, // do not collect native frames
CSTACK_FP, // walk stack using Frame Pointer links
CSTACK_DWARF, // use DWARF unwinding info from .eh_frame section
CSTACK_LBR, // Last Branch Record hardware capability
CSTACK_VM // unwind using HotSpot VMStructs (vmx mode uses CSTACK_VM with _features.mixed=1)
};
enum Output { OUTPUT_NONE, OUTPUT_COLLAPSED, OUTPUT_JFR };
enum JfrOption {
NO_SYSTEM_INFO = 0x1,
NO_SYSTEM_PROPS = 0x2,
NO_NATIVE_LIBS = 0x4,
NO_CPU_LOAD = 0x8,
JFR_SYNC_OPTS =
NO_SYSTEM_INFO | NO_SYSTEM_PROPS | NO_NATIVE_LIBS | NO_CPU_LOAD
};
enum WallclockSampler {
ASGCT,
JVMTI
};
enum Clock {
CLK_DEFAULT,
CLK_TSC,
CLK_MONOTONIC
};
// Keep this in sync with JfrSync.java
enum EventMask {
EM_CPU = 1,
EM_ALLOC = 2,
EM_LOCK = 4,
EM_WALL = 8,
EM_NATIVEMEM = 16,
EM_METHOD_TRACE = 32
};
constexpr int EVENT_MASK_SIZE = 6;
struct StackWalkFeatures {
// Deprecated stack recovery techniques used to workaround AsyncGetCallTrace flaws
unsigned short unknown_java : 1;
unsigned short unwind_stub : 1;
unsigned short unwind_comp : 1;
unsigned short unwind_native : 1;
unsigned short java_anchor : 1;
unsigned short gc_traces : 1;
// Common features
unsigned short stats : 1; // collect stack walking duration statistics
// Additional HotSpot-specific features
unsigned short jnienv : 1; // verify JNIEnv* obtained using VMStructs
unsigned short probe_sp : 1; // when AsyncGetCallTrace fails, adjust SP and retry
unsigned short mixed : 1; // mixed stack traces with Java and native frames interleaved
unsigned short vtable_target : 1; // show receiver classes of vtable/itable stubs
unsigned short comp_task : 1; // display current compilation task for JIT threads
unsigned short pc_addr : 1; // record exact PC address for each sample
unsigned short _padding : 3; // pad structure to 16 bits
};
struct Multiplier {
char symbol;
long multiplier;
};
class Error {
private:
const char *_message;
public:
static const Error OK;
explicit Error(const char *message) : _message(message) {}
const char *message() { return _message; }
operator bool() { return _message != NULL; }
};
class Arguments {
private:
char *_buf;
bool _shared;
bool _persistent;
const char *expandFilePattern(const char *pattern);
static long long hash(const char *arg);
static long parseUnits(const char *str, const Multiplier *multipliers);
static bool isCpuEvent(const char *event) {
// event == NULL will default to EVENT_CPU
return event == NULL || strcmp(event, EVENT_CPU) == 0 ||
strcmp(event, EVENT_ITIMER) == 0 || strcmp(event, EVENT_CTIMER) == 0;
}
public:
Action _action;
Ring _ring;
const char *_event;
long _interval;
long _cpu;
long _wall;
bool _wall_collapsing;
int _wall_threads_per_tick;
WallclockSampler _wallclock_sampler;
long _memory;
bool _record_allocations;
bool _record_liveness;
double _live_samples_ratio;
bool _record_heap_usage;
bool _gc_generations;
long _nativemem;
int _jstackdepth;
int _safe_mode;
StackWalkFeatures _features;
const char* _file;
const char* _log;
const char* _loglevel;
const char* _unknown_arg;
const char* _filter;
CStack _cstack;
Clock _clock;
int _jfr_options;
std::vector<std::string> _context_attributes;
bool _lightweight;
bool _enable_method_cleanup;
bool _remote_symbolication; // Enable remote symbolication for native frames
Arguments(bool persistent = false)
: _buf(NULL),
_shared(false),
_persistent(persistent),
_action(ACTION_NONE),
_ring(RING_ANY),
_event(NULL),
_interval(0),
_cpu(-1),
_wall(-1),
_wall_collapsing(false),
_wall_threads_per_tick(DEFAULT_WALL_THREADS_PER_TICK),
_memory(-1),
_record_allocations(false),
_record_liveness(false),
_live_samples_ratio(0.1), // default to liveness-tracking 10% of the allocation samples
_record_heap_usage(false),
_gc_generations(false),
_nativemem(-1),
_jstackdepth(DEFAULT_JSTACKDEPTH),
_safe_mode(0),
_features{1, 1, 1, 1, 1, 1},
_file(NULL),
_log(NULL),
_loglevel(NULL),
_unknown_arg(NULL),
_filter(NULL),
_cstack(CSTACK_DEFAULT),
_clock(CLK_DEFAULT),
_jfr_options(0),
_context_attributes({}),
_wallclock_sampler(ASGCT),
_lightweight(false),
_enable_method_cleanup(true),
_remote_symbolication(false) {}
~Arguments();
void save(Arguments &other);
Error parse(const char *args);
const char *file();
bool hasOption(JfrOption option) const {
return (_jfr_options & option) != 0;
}
long cpuSamplerInterval() const {
return isCpuEvent(_event) ? (_cpu > 0 ? _cpu
: _interval > 0 ? _interval
: DEFAULT_CPU_INTERVAL)
: 0;
}
friend class FrameName;
friend class Recording;
};
#endif // _ARGUMENTS_H