forked from stackimpact/stackimpact-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackImpact.java
More file actions
229 lines (161 loc) · 6.25 KB
/
StackImpact.java
File metadata and controls
229 lines (161 loc) · 6.25 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
package com.stackimpact.agent;
import java.util.Map;
import java.lang.instrument.Instrumentation;
public class StackImpact {
public static String getDashboardAddress() {
Agent agent = Agent.getInstance();
return agent.getDashboardAddress();
}
public static void setDashboardAddress(String dashboardAddress) {
Agent agent = Agent.getInstance();
agent.setDashboardAddress(dashboardAddress);
}
public static String getAgentKey() {
Agent agent = Agent.getInstance();
return agent.getAgentKey();
}
public static void setAgentKey(String agentKey) {
Agent agent = Agent.getInstance();
agent.setAgentKey(agentKey);
}
public static String getAppName() {
Agent agent = Agent.getInstance();
return agent.getAppName();
}
public static void setAppName(String appName) {
Agent agent = Agent.getInstance();
agent.setAppName(appName);
}
public static String getAppVersion() {
Agent agent = Agent.getInstance();
return agent.getAppVersion();
}
public static void setAppVersion(String appVersion) {
Agent agent = Agent.getInstance();
agent.setAppVersion(appVersion);
}
public static String getAppEnvironment() {
Agent agent = Agent.getInstance();
return agent.getAppEnvironment();
}
public static void setAppEnvironment(String appEnvironment) {
Agent agent = Agent.getInstance();
agent.setAppEnvironment(appEnvironment);
}
public static String getHostName() {
Agent agent = Agent.getInstance();
return agent.getHostName();
}
public static void setHostName(String hostName) {
Agent agent = Agent.getInstance();
agent.setHostName(hostName);
}
public static boolean isAutoProfilingMode() {
Agent agent = Agent.getInstance();
return agent.isAutoProfilingMode();
}
public static void setAutoProfilingMode(boolean isAutoProfilingMode) {
Agent agent = Agent.getInstance();
agent.setAutoProfilingMode(isAutoProfilingMode);
}
public static boolean isCPUProfilerDisabled() {
Agent agent = Agent.getInstance();
return agent.isCPUProfilerDisabled();
}
public static void setCPUProfilerDisabled(boolean isCPUProfilerDisabled) {
Agent agent = Agent.getInstance();
agent.setCPUProfilerDisabled(isCPUProfilerDisabled);
}
public static boolean isAllocationProfilerDisabled() {
Agent agent = Agent.getInstance();
return agent.isAllocationProfilerDisabled();
}
public static void setAllocationProfilerDisabled(boolean isAllocationProfilerDisabled) {
Agent agent = Agent.getInstance();
agent.setAllocationProfilerDisabled(isAllocationProfilerDisabled);
}
public static boolean isLockProfilerDisabled() {
Agent agent = Agent.getInstance();
return agent.isLockProfilerDisabled();
}
public static void setLockProfilerDisabled(boolean isLockProfilerDisabled) {
Agent agent = Agent.getInstance();
agent.setLockProfilerDisabled(isLockProfilerDisabled);
}
public static boolean isDebugMode() {
Agent agent = Agent.getInstance();
return agent.isDebugMode();
}
public static void setDebugMode(boolean isDebugMode) {
Agent agent = Agent.getInstance();
agent.setDebugMode(isDebugMode);
}
public static boolean isAgentFramesEnabled() {
Agent agent = Agent.getInstance();
return agent.isAgentFramesEnabled();
}
public static void setAgentFramesEnabled(boolean isAgentFramesEnabled) {
Agent agent = Agent.getInstance();
agent.setAgentFramesEnabled(isAgentFramesEnabled);
}
public static void start(String agentKey, String appName) {
Agent agent = Agent.getInstance();
agent.start(agentKey, appName);
}
public static void destroy() {
Agent agent = Agent.getInstance();
agent.destroy();
}
public static ProfileSpan profile() {
Agent agent = Agent.getInstance();
return agent.profile();
}
private static String getJVMOption(Map<String, String> env, String key) {
key = "si." + key;
String val = System.getProperty(key);
if (val != null) {
return val;
}
else {
return env.get(key.toUpperCase().replace('.', '_'));
}
}
// only used if the agent is loaded via javaagent command line option
public static void premain(String args, Instrumentation instrumentation) {
Agent agent = Agent.getInstance();
Map<String, String> env = System.getenv();
String dashboardAddress = getJVMOption(env, "dashboard.address");
if (dashboardAddress != null) {
agent.setDashboardAddress(dashboardAddress);
}
String appVersion = getJVMOption(env, "app.version");
if (appVersion != null) {
agent.setAppVersion(appVersion);
}
String appEnvironment = getJVMOption(env, "app.environmnet");
if (appEnvironment != null) {
agent.setAppEnvironment(appEnvironment);
}
String hostName = getJVMOption(env, "host.name");
if (hostName != null) {
agent.setHostName(hostName);
}
String debugMode = getJVMOption(env, "debug.mode");
if (debugMode != null) {
agent.setDebugMode("true".equalsIgnoreCase(debugMode));
}
String isCPUProfilerDisabled = getJVMOption(env, "cpu.profiler.disabled");
if (isCPUProfilerDisabled != null) {
agent.setCPUProfilerDisabled("true".equalsIgnoreCase(isCPUProfilerDisabled));
}
String isLockProfilerDisabled = getJVMOption(env, "lock.profiler.disabled");
if (isLockProfilerDisabled != null) {
agent.setLockProfilerDisabled("true".equalsIgnoreCase(isLockProfilerDisabled));
}
String isAgentFramesEnabled = getJVMOption(env, "agent.frames.enabled");
if (isAgentFramesEnabled != null) {
agent.setAgentFramesEnabled("true".equalsIgnoreCase(isAgentFramesEnabled));
}
agent.start(getJVMOption(env, "agent.key"), getJVMOption(env, "app.name"));
}
}