< prev index next >

src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdDump.java

Print this page


   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


 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


 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             var dest = recording.getDestination();
 128             if ((filename == null) && (dest != null)) {
 129                 filename = dest.toString();
 130             }
 131         }
 132         PlatformRecorder recorder = PrivateAccess.getInstance().getPlatformRecorder();
 133         synchronized (recorder) {
 134             dump(recorder, recording, name, filename, maxSize, pathToGcRoots, beginTime, endTime);
 135         }
 136         return getResult();
 137     }
 138 
 139     public void dump(PlatformRecorder recorder, Recording recording, String name, String filename, Long maxSize, Boolean pathToGcRoots, Instant beginTime, Instant endTime) throws DCmdException {
 140         try (PlatformRecording r = newSnapShot(recorder, recording, pathToGcRoots)) {
 141             r.filter(beginTime, endTime, maxSize);
 142             if (r.getChunks().isEmpty()) {
 143                 throw new DCmdException("Dump failed. No data found in the specified interval.");
 144             }
 145             SafePath dumpFile = resolvePath(recording, filename);
 146 
 147             // Needed for JVM
 148             Utils.touch(dumpFile.toPath());
 149             r.dumpStopped(new WriteableUserPath(dumpFile.toPath()));
 150             reportOperationComplete("Dumped", name, dumpFile);


< prev index next >