1 /*
2 * Copyright (c) 2012, 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 package jdk.jfr.internal.dcmd;
26
27 import java.io.IOException;
28 import java.nio.file.InvalidPathException;
29 import java.time.Duration;
30 import java.time.Instant;
31 import java.time.LocalDate;
32 import java.time.LocalDateTime;
33 import java.time.LocalTime;
34 import java.time.ZoneId;
35 import java.time.ZonedDateTime;
36 import java.time.format.DateTimeParseException;
37
38 import jdk.jfr.FlightRecorder;
39 import jdk.jfr.Recording;
40 import jdk.jfr.internal.LogLevel;
41 import jdk.jfr.internal.LogTag;
42 import jdk.jfr.internal.Logger;
43 import jdk.jfr.internal.PlatformRecorder;
44 import jdk.jfr.internal.PlatformRecording;
45 import jdk.jfr.internal.PrivateAccess;
46 import jdk.jfr.internal.SecuritySupport.SafePath;
47 import jdk.jfr.internal.Utils;
48 import jdk.jfr.internal.WriteableUserPath;
107 }
108 }
109
110 Instant beginTime = parseTime(begin, "begin");
111 Instant endTime = parseTime(end, "end");
112
113 if (beginTime != null && endTime != null) {
114 if (endTime.isBefore(beginTime)) {
115 throw new DCmdException("Dump failed, begin must preceed end.");
116 }
117 }
118
119 Duration duration = null;
120 if (maxAge != null) {
121 duration = Duration.ofNanos(maxAge);
122 beginTime = Instant.now().minus(duration);
123 }
124 Recording recording = null;
125 if (name != null) {
126 recording = findRecording(name);
127 }
128 PlatformRecorder recorder = PrivateAccess.getInstance().getPlatformRecorder();
129 synchronized (recorder) {
130 dump(recorder, recording, name, filename, maxSize, pathToGcRoots, beginTime, endTime);
131 }
132 return getResult();
133 }
134
135 public void dump(PlatformRecorder recorder, Recording recording, String name, String filename, Long maxSize, Boolean pathToGcRoots, Instant beginTime, Instant endTime) throws DCmdException {
136 try (PlatformRecording r = newSnapShot(recorder, recording, pathToGcRoots)) {
137 r.filter(beginTime, endTime, maxSize);
138 if (r.getChunks().isEmpty()) {
139 throw new DCmdException("Dump failed. No data found in the specified interval.");
140 }
141 SafePath dumpFile = resolvePath(recording, filename);
142
143 // Needed for JVM
144 Utils.touch(dumpFile.toPath());
145 r.dumpStopped(new WriteableUserPath(dumpFile.toPath()));
146 reportOperationComplete("Dumped", name, dumpFile);
|
1 /*
2 * Copyright (c) 2012, 2019, 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 package jdk.jfr.internal.dcmd;
26
27 import java.io.IOException;
28 import java.nio.file.InvalidPathException;
29 import java.nio.file.Path;
30 import java.time.Duration;
31 import java.time.Instant;
32 import java.time.LocalDate;
33 import java.time.LocalDateTime;
34 import java.time.LocalTime;
35 import java.time.ZoneId;
36 import java.time.ZonedDateTime;
37 import java.time.format.DateTimeParseException;
38
39 import jdk.jfr.FlightRecorder;
40 import jdk.jfr.Recording;
41 import jdk.jfr.internal.LogLevel;
42 import jdk.jfr.internal.LogTag;
43 import jdk.jfr.internal.Logger;
44 import jdk.jfr.internal.PlatformRecorder;
45 import jdk.jfr.internal.PlatformRecording;
46 import jdk.jfr.internal.PrivateAccess;
47 import jdk.jfr.internal.SecuritySupport.SafePath;
48 import jdk.jfr.internal.Utils;
49 import jdk.jfr.internal.WriteableUserPath;
108 }
109 }
110
111 Instant beginTime = parseTime(begin, "begin");
112 Instant endTime = parseTime(end, "end");
113
114 if (beginTime != null && endTime != null) {
115 if (endTime.isBefore(beginTime)) {
116 throw new DCmdException("Dump failed, begin must preceed end.");
117 }
118 }
119
120 Duration duration = null;
121 if (maxAge != null) {
122 duration = Duration.ofNanos(maxAge);
123 beginTime = Instant.now().minus(duration);
124 }
125 Recording recording = null;
126 if (name != null) {
127 recording = findRecording(name);
128 Path dest = recording.getDestination();
129 if ((filename == null) && (dest != null)) {
130 filename = dest.toString();
131 }
132 }
133 PlatformRecorder recorder = PrivateAccess.getInstance().getPlatformRecorder();
134 synchronized (recorder) {
135 dump(recorder, recording, name, filename, maxSize, pathToGcRoots, beginTime, endTime);
136 }
137 return getResult();
138 }
139
140 public void dump(PlatformRecorder recorder, Recording recording, String name, String filename, Long maxSize, Boolean pathToGcRoots, Instant beginTime, Instant endTime) throws DCmdException {
141 try (PlatformRecording r = newSnapShot(recorder, recording, pathToGcRoots)) {
142 r.filter(beginTime, endTime, maxSize);
143 if (r.getChunks().isEmpty()) {
144 throw new DCmdException("Dump failed. No data found in the specified interval.");
145 }
146 SafePath dumpFile = resolvePath(recording, filename);
147
148 // Needed for JVM
149 Utils.touch(dumpFile.toPath());
150 r.dumpStopped(new WriteableUserPath(dumpFile.toPath()));
151 reportOperationComplete("Dumped", name, dumpFile);
|