Skip to content
Permalink
Browse files
8241033: Create test library utility for getting JFR streaming reposi…
…tory

New method to get JFR streaming repo path

Reviewed-by: egahlin, mgronlun
  • Loading branch information
Mikhailo Seledtsov committed Mar 18, 2020
1 parent f2fb5c5 commit 0ee74979373c43b643963e70141c3da3c1f9b6be
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, 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
@@ -34,12 +34,12 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

import com.sun.tools.attach.VirtualMachine;
import jdk.jfr.Event;
import jdk.jfr.Name;
import jdk.jfr.Recording;
import jdk.jfr.consumer.EventStream;
import jdk.test.lib.Asserts;
import jdk.test.lib.jfr.StreamingUtils;
import jdk.test.lib.process.ProcessTools;

/**
@@ -83,7 +83,7 @@

public static void main(String... args) throws Exception {
Process process = EventProducer.start();
Path repo = getJfrRepository(process);
Path repo = StreamingUtils.getJfrRepository(process);

// Consume 1000 events in a first batch
CountDownLatch consumed = new CountDownLatch(1000);
@@ -164,16 +164,4 @@ static void signal(String name) throws Exception {
static boolean signalCheck(String name) throws Exception {
return Files.exists(Paths.get(".", name));
}

static Path getJfrRepository(Process p) throws Exception {
VirtualMachine vm = VirtualMachine.attach(String.valueOf(p.pid()));
while (true) {
String repo = vm.getSystemProperties().getProperty("jdk.jfr.repository");
if (repo != null) {
vm.detach();
System.out.println("JFR repository: " + repo);
return Paths.get(repo);
}
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, 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
@@ -34,6 +34,7 @@

import jdk.internal.misc.Unsafe;
import jdk.jfr.Event;
import jdk.test.lib.jfr.StreamingUtils;
import jdk.test.lib.process.ProcessTools;

import com.sun.tools.attach.VirtualMachine;
@@ -91,22 +92,8 @@ public static void main(String... args) throws Exception {
}
}

public Path getRepository() {
while (true) {
try {
VirtualMachine vm = VirtualMachine.attach(String.valueOf(process.pid()));
Properties p = vm.getSystemProperties();
vm.detach();
String repo = (String) p.get("jdk.jfr.repository");
if (repo != null) {
return Paths.get(repo);
}
} catch (Exception e) {
System.out.println("Attach failed: " + e.getMessage());
System.out.println("Retrying...");
}
takeNap();
}
public Path getRepository() throws Exception {
return StreamingUtils.getJfrRepository(process);
}

private static void takeNap() {
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2020, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.test.lib.jfr;

import com.sun.tools.attach.VirtualMachine;
import java.nio.file.Path;
import java.nio.file.Paths;


/**
* Utilities for testing JFR streaming.
*
*/
public class StreamingUtils {
/**
* Get path to JFR streaming repository for a given process, try until success or test timeout.
*
* @param process process to analyze
* @return Path to the JFR streaming repository, or null
*/
public static Path getJfrRepository(Process process) throws Exception {
while (true) {
if (!process.isAlive()) {
String msg = String.format("Process (pid = %d) is no longer alive, exit value = %d",
process.pid(), process.exitValue());
throw new RuntimeException(msg);
}

try {
VirtualMachine vm = VirtualMachine.attach(String.valueOf(process.pid()));
String repo = vm.getSystemProperties().getProperty("jdk.jfr.repository");
if (repo != null) {
vm.detach();
System.out.println("JFR repository: " + repo);
return Paths.get(repo);
}
} catch (Exception e) {
System.out.println("Attach failed: " + e.getMessage());
System.out.println("Retrying...");
}
Thread.sleep(500);
}
}

}

0 comments on commit 0ee7497

Please sign in to comment.