50113
|
1 |
/*
|
|
2 |
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package jdk.jfr.internal.dcmd;
|
|
27 |
|
|
28 |
|
|
29 |
|
57752
|
30 |
import jdk.jfr.FlightRecorder;
|
50113
|
31 |
import jdk.jfr.internal.LogLevel;
|
|
32 |
import jdk.jfr.internal.LogTag;
|
|
33 |
import jdk.jfr.internal.Logger;
|
|
34 |
import jdk.jfr.internal.Options;
|
57752
|
35 |
import jdk.jfr.internal.PrivateAccess;
|
50113
|
36 |
import jdk.jfr.internal.Repository;
|
|
37 |
import jdk.jfr.internal.SecuritySupport.SafePath;
|
|
38 |
|
|
39 |
/**
|
|
40 |
* JFR.configure - invoked from native
|
|
41 |
*
|
|
42 |
*/
|
|
43 |
//Instantiated by native
|
|
44 |
final class DCmdConfigure extends AbstractDCmd {
|
|
45 |
/**
|
|
46 |
* Execute JFR.configure.
|
|
47 |
*
|
|
48 |
* @param repositoryPath the path
|
|
49 |
* @param dumpPath path to dump to on fatal error (oom)
|
|
50 |
* @param stackDepth depth of stack traces
|
|
51 |
* @param globalBufferCount number of global buffers
|
|
52 |
* @param globalBufferSize size of global buffers
|
|
53 |
* @param threadBufferSize size of thread buffer for events
|
|
54 |
* @param maxChunkSize threshold at which a new chunk is created in the disk repository
|
|
55 |
* @param sampleThreads if thread sampling should be enabled
|
|
56 |
*
|
|
57 |
* @return result
|
|
58 |
|
|
59 |
* @throws DCmdException
|
|
60 |
* if the dump could not be completed
|
|
61 |
*/
|
|
62 |
public String execute
|
|
63 |
(
|
|
64 |
String repositoryPath,
|
|
65 |
String dumpPath,
|
|
66 |
Integer stackDepth,
|
|
67 |
Long globalBufferCount,
|
|
68 |
Long globalBufferSize,
|
|
69 |
Long threadBufferSize,
|
|
70 |
Long memorySize,
|
|
71 |
Long maxChunkSize,
|
|
72 |
Boolean sampleThreads
|
|
73 |
|
|
74 |
) throws DCmdException {
|
52413
|
75 |
if (Logger.shouldLog(LogTag.JFR_DCMD, LogLevel.DEBUG)) {
|
50745
|
76 |
Logger.log(LogTag.JFR_DCMD, LogLevel.DEBUG, "Executing DCmdConfigure: repositorypath=" + repositoryPath +
|
|
77 |
", dumppath=" + dumpPath +
|
|
78 |
", stackdepth=" + stackDepth +
|
|
79 |
", globalbuffercount=" + globalBufferCount +
|
|
80 |
", globalbuffersize=" + globalBufferSize +
|
|
81 |
", thread_buffer_size" + threadBufferSize +
|
|
82 |
", memorysize" + memorySize +
|
|
83 |
", maxchunksize=" + maxChunkSize +
|
|
84 |
", samplethreads" + sampleThreads);
|
|
85 |
}
|
|
86 |
|
|
87 |
|
50113
|
88 |
boolean updated = false;
|
|
89 |
if (repositoryPath != null) {
|
|
90 |
try {
|
|
91 |
SafePath s = new SafePath(repositoryPath);
|
|
92 |
Repository.getRepository().setBasePath(s);
|
|
93 |
Logger.log(LogTag.JFR, LogLevel.INFO, "Base repository path set to " + repositoryPath);
|
57752
|
94 |
if (FlightRecorder.isInitialized()) {
|
|
95 |
PrivateAccess.getInstance().getPlatformRecorder().rotateIfRecordingToDisk();;
|
|
96 |
}
|
50113
|
97 |
} catch (Exception e) {
|
|
98 |
throw new DCmdException("Could not use " + repositoryPath + " as repository. " + e.getMessage(), e);
|
|
99 |
}
|
|
100 |
printRepositoryPath();
|
|
101 |
updated = true;
|
|
102 |
}
|
|
103 |
|
|
104 |
if (dumpPath != null) {
|
|
105 |
Options.setDumpPath(new SafePath(dumpPath));
|
|
106 |
Logger.log(LogTag.JFR, LogLevel.INFO, "Emergency dump path set to " + dumpPath);
|
|
107 |
printDumpPath();
|
|
108 |
updated = true;
|
|
109 |
}
|
|
110 |
|
|
111 |
if (stackDepth != null) {
|
|
112 |
Options.setStackDepth(stackDepth);
|
|
113 |
Logger.log(LogTag.JFR, LogLevel.INFO, "Stack depth set to " + stackDepth);
|
|
114 |
printStackDepth();
|
|
115 |
updated = true;
|
|
116 |
}
|
|
117 |
|
|
118 |
if (globalBufferCount != null) {
|
|
119 |
Options.setGlobalBufferCount(globalBufferCount);
|
|
120 |
Logger.log(LogTag.JFR, LogLevel.INFO, "Global buffer count set to " + globalBufferCount);
|
|
121 |
printGlobalBufferCount();
|
|
122 |
updated = true;
|
|
123 |
}
|
|
124 |
|
|
125 |
if (globalBufferSize != null) {
|
|
126 |
Options.setGlobalBufferSize(globalBufferSize);
|
|
127 |
Logger.log(LogTag.JFR, LogLevel.INFO, "Global buffer size set to " + globalBufferSize);
|
|
128 |
printGlobalBufferSize();
|
|
129 |
updated = true;
|
|
130 |
}
|
|
131 |
|
|
132 |
if (threadBufferSize != null) {
|
|
133 |
Options.setThreadBufferSize(threadBufferSize);
|
|
134 |
Logger.log(LogTag.JFR, LogLevel.INFO, "Thread buffer size set to " + threadBufferSize);
|
|
135 |
printThreadBufferSize();
|
|
136 |
updated = true;
|
|
137 |
}
|
|
138 |
|
|
139 |
if (memorySize != null) {
|
|
140 |
Options.setMemorySize(memorySize);
|
|
141 |
Logger.log(LogTag.JFR, LogLevel.INFO, "Memory size set to " + memorySize);
|
|
142 |
printMemorySize();
|
|
143 |
updated = true;
|
|
144 |
}
|
|
145 |
|
|
146 |
if (maxChunkSize != null) {
|
|
147 |
Options.setMaxChunkSize(maxChunkSize);
|
|
148 |
Logger.log(LogTag.JFR, LogLevel.INFO, "Max chunk size set to " + maxChunkSize);
|
|
149 |
printMaxChunkSize();
|
|
150 |
updated = true;
|
|
151 |
}
|
|
152 |
|
|
153 |
if (sampleThreads != null) {
|
|
154 |
Options.setSampleThreads(sampleThreads);
|
|
155 |
Logger.log(LogTag.JFR, LogLevel.INFO, "Sample threads set to " + sampleThreads);
|
|
156 |
printSampleThreads();
|
|
157 |
updated = true;
|
|
158 |
}
|
|
159 |
|
|
160 |
if (!updated) {
|
|
161 |
println("Current configuration:");
|
|
162 |
println();
|
|
163 |
printRepositoryPath();
|
|
164 |
printStackDepth();
|
|
165 |
printGlobalBufferCount();
|
|
166 |
printGlobalBufferSize();
|
|
167 |
printThreadBufferSize();
|
|
168 |
printMemorySize();
|
|
169 |
printMaxChunkSize();
|
|
170 |
printSampleThreads();
|
|
171 |
}
|
|
172 |
return getResult();
|
|
173 |
}
|
|
174 |
|
|
175 |
private void printRepositoryPath() {
|
|
176 |
print("Repository path: ");
|
|
177 |
printPath(Repository.getRepository().getRepositoryPath());
|
|
178 |
println();
|
|
179 |
}
|
|
180 |
|
|
181 |
private void printDumpPath() {
|
|
182 |
print("Dump path: ");
|
|
183 |
printPath(Options.getDumpPath());
|
|
184 |
println();
|
|
185 |
}
|
|
186 |
|
|
187 |
private void printSampleThreads() {
|
|
188 |
println("Sample threads: " + Options.getSampleThreads());
|
|
189 |
}
|
|
190 |
|
|
191 |
private void printStackDepth() {
|
|
192 |
println("Stack depth: " + Options.getStackDepth());
|
|
193 |
}
|
|
194 |
|
|
195 |
private void printGlobalBufferCount() {
|
|
196 |
println("Global buffer count: " + Options.getGlobalBufferCount());
|
|
197 |
}
|
|
198 |
|
|
199 |
private void printGlobalBufferSize() {
|
|
200 |
print("Global buffer size: ");
|
53013
|
201 |
printBytes(Options.getGlobalBufferSize());
|
50113
|
202 |
println();
|
|
203 |
}
|
|
204 |
|
|
205 |
private void printThreadBufferSize() {
|
|
206 |
print("Thread buffer size: ");
|
53013
|
207 |
printBytes(Options.getThreadBufferSize());
|
50113
|
208 |
println();
|
|
209 |
}
|
|
210 |
|
|
211 |
private void printMemorySize() {
|
|
212 |
print("Memory size: ");
|
53013
|
213 |
printBytes(Options.getMemorySize());
|
50113
|
214 |
println();
|
|
215 |
}
|
|
216 |
|
|
217 |
private void printMaxChunkSize() {
|
|
218 |
print("Max chunk size: ");
|
53013
|
219 |
printBytes(Options.getMaxChunkSize());
|
50113
|
220 |
println();
|
|
221 |
}
|
|
222 |
}
|