Skip to content

Commit

Permalink
8269225: JFR.stop misses the written info when the filename is only s…
Browse files Browse the repository at this point in the history
…pecified by JFR.start

Reviewed-by: egahlin
  • Loading branch information
D-D-H authored and y1yang0 committed Jun 25, 2021
1 parent 3a8f3d6 commit fd43d9c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Expand Up @@ -29,7 +29,9 @@
import java.nio.file.Paths;

import jdk.jfr.Recording;
import jdk.jfr.internal.PrivateAccess;
import jdk.jfr.internal.SecuritySupport.SafePath;
import jdk.jfr.internal.WriteableUserPath;

/**
* JFR.stop
Expand All @@ -44,8 +46,9 @@ protected void execute(ArgumentParser parser) throws DCmdException {
String name = parser.getOption("name");
String filename = parser.getOption("filename");
try {
SafePath safePath = null;
Recording recording = findRecording(name);
WriteableUserPath path = PrivateAccess.getInstance().getPlatformRecording(recording).getDestination();
SafePath safePath = path == null ? null : new SafePath(path.getRealPathText());
if (filename != null) {
try {
// Ensure path is valid. Don't generate safePath if filename == null, as a user may
Expand Down
50 changes: 50 additions & 0 deletions test/jdk/jdk/jfr/jcmd/TestJcmdStopWithoutFilename.java
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2021, Alibaba Group Holding Limited. 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.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package jdk.jfr.jcmd;

import jdk.test.lib.process.OutputAnalyzer;

/**
* @test
* @summary The test verifies JFR.stop
* @key jfr
* @requires vm.hasJFR
* @library /test/lib /test/jdk
* @run main/othervm jdk.jfr.jcmd.TestJcmdStopWithoutFilename
*/
public class TestJcmdStopWithoutFilename {

public static void main(String[] args) throws Exception {

JcmdHelper.jcmd("JFR.start name=test");
OutputAnalyzer output = JcmdHelper.jcmd("JFR.stop name=test");
output.shouldNotContain("written to");

String filename = "output.jfr";
JcmdHelper.jcmd("JFR.start name=test filename=" + filename);
output = JcmdHelper.jcmd("JFR.stop name=test");
output.shouldContain("written to").shouldContain(filename);
}
}

1 comment on commit fd43d9c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.