提交 fca576bf 编写于 作者: D Denghui Dong 提交者: D-D-H

[Backport] 8236264: Remove jdk.jfr.Recording::setFlushInterval and...

[Backport] 8236264: Remove jdk.jfr.Recording::setFlushInterval and jdk.jfr.Recording::getFlushInterval

Summary:

Test Plan: jdk/jfr

Reviewed-by: yuleil

Issue: https://github.com/alibaba/dragonwell8/issues/112
上级 d4a636fd
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 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
......@@ -424,7 +424,7 @@ public final class Recording implements Closeable {
*
* @since 14
*/
public void setFlushInterval(Duration interval) {
/*package private*/ void setFlushInterval(Duration interval) {
Objects.nonNull(interval);
if (interval.isNegative()) {
throw new IllegalArgumentException("Stream interval can't be negative");
......@@ -439,7 +439,7 @@ public final class Recording implements Closeable {
*
* @since 14
*/
public Duration getFlushInterval() {
/*package private*/ Duration getFlushInterval() {
return internal.getFlushInterval();
}
......
/*
* 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
......@@ -86,7 +86,6 @@ public final class RecordingStream implements AutoCloseable, EventStream {
Utils.checkAccessFlightRecorder();
AccessControlContext acc = AccessController.getContext();
this.recording = new Recording();
this.recording.setFlushInterval(Duration.ofMillis(1000));
try {
PlatformRecording pr = PrivateAccess.getInstance().getPlatformRecording(recording);
this.directoryStream = new EventDirectoryStream(acc, null, SecuritySupport.PRIVILIGED, pr);
......@@ -267,20 +266,6 @@ public final class RecordingStream implements AutoCloseable, EventStream {
recording.setMaxSize(maxSize);
}
/**
* Determines how often events are made available for streaming.
*
* @param interval the interval at which events are made available to the
* stream, no {@code null}
*
* @throws IllegalArgumentException if {@code interval} is negative
*
* @throws IllegalStateException if the stream is closed
*/
public void setFlushInterval(Duration interval) {
recording.setFlushInterval(interval);
}
@Override
public void setReuse(boolean reuse) {
directoryStream.setReuse(reuse);
......
/*
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
......@@ -45,6 +45,7 @@ import jdk.jfr.internal.LogTag;
import jdk.jfr.internal.Logger;
import jdk.jfr.internal.Options;
import jdk.jfr.internal.OldObjectSample;
import jdk.jfr.internal.PlatformRecording;
import jdk.jfr.internal.PrivateAccess;
import jdk.jfr.internal.SecuritySupport.SafePath;
import jdk.jfr.internal.Type;
......@@ -196,7 +197,8 @@ final class DCmdStart extends AbstractDCmd {
}
if (flush != null) {
recording.setFlushInterval(Duration.ofNanos(flush));
PlatformRecording p = PrivateAccess.getInstance().getPlatformRecording(recording);
p.setFlushInterval(Duration.ofNanos(flush));
}
if (maxSize != null) {
......
/*
* 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
......@@ -77,7 +77,6 @@ public final class TestSetEndTime {
CountDownLatch closed = new CountDownLatch(1);
AtomicInteger count = new AtomicInteger();
try (RecordingStream rs = new RecordingStream()) {
rs.setFlushInterval(Duration.ofSeconds(1));
rs.onEvent(e -> {
count.incrementAndGet();
});
......
/*
* Copyright (c) 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
* 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.jfr.api.consumer.recordingstream;
import java.time.Duration;
import jdk.jfr.consumer.RecordingStream;
import jdk.test.lib.jfr.EventNames;
/**
* @test
* @summary Tests RecordingStream::setFlushInterval
* @key jfr
* @library /lib /
* @run main/othervm jdk.jfr.api.consumer.recordingstream.TestSetFlushInterval
*/
public class TestSetFlushInterval {
public static void main(String... args) throws Exception {
Duration expectedDuration = Duration.ofMillis(1001);
try (RecordingStream r = new RecordingStream()) {
r.setFlushInterval(expectedDuration);
r.enable(EventNames.ActiveRecording);
r.onEvent(e -> {
System.out.println(e);
Duration duration = e.getDuration("flushInterval");
if (expectedDuration.equals(duration)) {
System.out.println("Closing recording");
r.close();
return;
}
System.out.println("Flush interval not set, was " + duration +
", but expected " + expectedDuration);
});
r.start();
}
}
}
/*
* 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
......@@ -73,7 +73,6 @@ public class TestStreamingRemote {
public static void main(String... args) throws Exception {
try (Recording r = new Recording()) {
r.setFlushInterval(Duration.ofSeconds(1));
r.start();
String repository = System.getProperty("jdk.jfr.repository");
Path policy = createPolicyFile(repository);
......
/*
* 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
......@@ -70,7 +70,6 @@ public class TestInProcessMigration {
System.out.println("Started es.startAsync()");
try (Recording r = new Recording()) {
r.setFlushInterval(Duration.ofSeconds(1));
r.start();
// Chunk in default repository
MigrationEvent e1 = new MigrationEvent();
......
/*
* Copyright (c) 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
* 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.jfr.api.recording.time;
import java.time.Duration;
import java.util.concurrent.CountDownLatch;
import jdk.jfr.Recording;
import jdk.jfr.consumer.EventStream;
import jdk.test.lib.Asserts;
/**
* @test
* @key jfr
* @summary Test Recording::SetFlushInterval(...) and
* Recording::getFlushInterval()
* @library /lib /
* @run main/othervm jdk.jfr.api.recording.time.TestSetFlushInterval
*/
public class TestSetFlushInterval {
public static void main(String[] args) throws Throwable {
testSetGet();
testSetNull();
testFlush();
}
static void testFlush() throws Exception {
CountDownLatch flush = new CountDownLatch(1);
try (EventStream es = EventStream.openRepository()) {
es.onFlush(() -> {
flush.countDown();
});
es.startAsync();
try (Recording r = new Recording()) {
r.setFlushInterval(Duration.ofSeconds(1));
r.start();
flush.await();
}
}
}
static void testSetNull() {
try (Recording r = new Recording()) {
r.setFlushInterval(null);
Asserts.fail("Expected NullPointerException");
} catch (NullPointerException npe) {
// as expected
}
}
static void testSetGet() {
try (Recording r = new Recording()) {
Duration a = Duration.ofNanos(21378461289374646L);
r.setFlushInterval(a);
Duration b = r.getFlushInterval();
Asserts.assertEQ(a, b);
}
}
}
/*
* 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
......@@ -29,20 +29,25 @@ import java.time.Duration;
import jdk.jfr.FlightRecorder;
import jdk.jfr.Recording;
import jdk.jfr.internal.PlatformRecording;
import jdk.jfr.internal.PrivateAccess;
/**
* @test
* @summary Start a recording with a flush interval
* @key jfr
* @library /lib /
* @run main/othervm -XX:StartFlightRecording=flush-interval=1s jdk.jfr.startupargs.TestFlushInterval
* @modules jdk.jfr/jdk.jfr.internal
* @run main/othervm -XX:StartFlightRecording=flush-interval=2s jdk.jfr.startupargs.TestFlushInterval
*/
public class TestFlushInterval {
public static void main(String[] args) throws Exception {
for (Recording r : FlightRecorder.getFlightRecorder().getRecordings()) {
Duration d = r.getFlushInterval();
if (d.equals(Duration.ofSeconds(1))) {
PrivateAccess p = PrivateAccess.getInstance();
PlatformRecording pr = p.getPlatformRecording(r);
Duration d = pr.getFlushInterval();
if (d.equals(Duration.ofSeconds(2))) {
return; //OK
} else {
throw new Exception("Unexpected flush-interval " + d);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册