< prev index next >

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

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 23,32 **** --- 23,33 ---- * questions. */ package jdk.jfr.internal.dcmd; import java.io.IOException; + import java.nio.file.Files; import java.nio.file.InvalidPathException; import java.time.Duration; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime;
*** 122,146 **** beginTime = Instant.now().minus(duration); } Recording recording = null; if (name != null) { recording = findRecording(name); } PlatformRecorder recorder = PrivateAccess.getInstance().getPlatformRecorder(); synchronized (recorder) { ! dump(recorder, recording, name, filename, maxSize, pathToGcRoots, beginTime, endTime); } return getResult(); } ! public void dump(PlatformRecorder recorder, Recording recording, String name, String filename, Long maxSize, Boolean pathToGcRoots, Instant beginTime, Instant endTime) throws DCmdException { try (PlatformRecording r = newSnapShot(recorder, recording, pathToGcRoots)) { r.filter(beginTime, endTime, maxSize); if (r.getChunks().isEmpty()) { throw new DCmdException("Dump failed. No data found in the specified interval."); } - SafePath dumpFile = resolvePath(recording, filename); // Needed for JVM Utils.touch(dumpFile.toPath()); r.dumpStopped(new WriteableUserPath(dumpFile.toPath())); reportOperationComplete("Dumped", name, dumpFile); --- 123,164 ---- beginTime = Instant.now().minus(duration); } Recording recording = null; if (name != null) { recording = findRecording(name); + PlatformRecording pr = PrivateAccess.getInstance().getPlatformRecording(recording); + WriteableUserPath currentDest = pr.getDestination(); + if ((filename == null) && (currentDest != null)) { + filename = currentDest.getText(); + } + } + SafePath dumpFile = resolvePath(recording, filename); + try { + // Privileges check: + // c'tor of WriteableUserPath will create a file. + // So we need to remove it at this point. + boolean notExists = Files.notExists(dumpFile.toPath()); + new WriteableUserPath(dumpFile.toPath()); + if (notExists) { + Files.delete(dumpFile.toPath()); + } + } catch (IOException e) { + throw new DCmdException(e, e.getMessage()); } PlatformRecorder recorder = PrivateAccess.getInstance().getPlatformRecorder(); synchronized (recorder) { ! dump(recorder, recording, name, dumpFile, maxSize, pathToGcRoots, beginTime, endTime); } return getResult(); } ! public void dump(PlatformRecorder recorder, Recording recording, String name, SafePath dumpFile, Long maxSize, Boolean pathToGcRoots, Instant beginTime, Instant endTime) throws DCmdException { try (PlatformRecording r = newSnapShot(recorder, recording, pathToGcRoots)) { r.filter(beginTime, endTime, maxSize); if (r.getChunks().isEmpty()) { throw new DCmdException("Dump failed. No data found in the specified interval."); } // Needed for JVM Utils.touch(dumpFile.toPath()); r.dumpStopped(new WriteableUserPath(dumpFile.toPath())); reportOperationComplete("Dumped", name, dumpFile);
< prev index next >