mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
8367948: JFR: MethodTrace threshold setting has no effect
Reviewed-by: shade
This commit is contained in:
parent
02c78bb47e
commit
4bc86a26db
@ -49,7 +49,7 @@ public final class MethodTraceEvent extends AbstractJDKEvent {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static boolean enabled() {
|
||||
public static boolean shouldCommit(long duration) {
|
||||
// Generated by JFR
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ public final class MethodTracer {
|
||||
public static void traceObjectInit(long startTime, long methodId) {
|
||||
long endTime = JVM.counterTime();
|
||||
long duration = endTime - startTime;
|
||||
if (MethodTraceEvent.enabled() && JVM.getEventWriter() != null) {
|
||||
if (MethodTraceEvent.shouldCommit(duration) && JVM.getEventWriter() != null) {
|
||||
MethodTraceEvent.commit(startTime, duration, methodId);
|
||||
}
|
||||
}
|
||||
@ -66,7 +66,7 @@ public final class MethodTracer {
|
||||
public static void traceTimingObjectInit(long startTime, long methodId) {
|
||||
long endTime = JVM.counterTime();
|
||||
long duration = endTime - startTime;
|
||||
if (MethodTraceEvent.enabled() && JVM.getEventWriter() != null) {
|
||||
if (MethodTraceEvent.shouldCommit(duration) && JVM.getEventWriter() != null) {
|
||||
MethodTraceEvent.commit(startTime, duration, methodId);
|
||||
}
|
||||
if (MethodTimingEvent.enabled()) {
|
||||
@ -77,7 +77,7 @@ public final class MethodTracer {
|
||||
public static void trace(long startTime, long methodId) {
|
||||
long endTime = JVM.counterTime();
|
||||
long duration = endTime - startTime;
|
||||
if (MethodTraceEvent.enabled()) {
|
||||
if (MethodTraceEvent.shouldCommit(duration)) {
|
||||
MethodTraceEvent.commit(startTime, duration, methodId);
|
||||
}
|
||||
}
|
||||
@ -96,7 +96,7 @@ public final class MethodTracer {
|
||||
if (MethodTimingEvent.enabled()) {
|
||||
PlatformTracer.addTiming(methodId, duration);
|
||||
}
|
||||
if (MethodTraceEvent.enabled()) {
|
||||
if (MethodTraceEvent.shouldCommit(duration)) {
|
||||
MethodTraceEvent.commit(startTime, duration, methodId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,8 @@
|
||||
*/
|
||||
package jdk.jfr.event.tracing;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import jdk.jfr.Event;
|
||||
@ -29,7 +31,9 @@ import jdk.jfr.StackTrace;
|
||||
import jdk.jfr.consumer.RecordedEvent;
|
||||
import jdk.jfr.consumer.RecordedMethod;
|
||||
import jdk.jfr.consumer.RecordingStream;
|
||||
import jdk.jfr.Recording;
|
||||
|
||||
import jdk.test.lib.jfr.Events;
|
||||
/**
|
||||
* @test
|
||||
* @summary Basic test of the MethodTrace event.
|
||||
@ -52,6 +56,31 @@ public class TestMethodTrace {
|
||||
}
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
testWithoutThreshold();
|
||||
testWithThreshold();
|
||||
}
|
||||
|
||||
private static void testWithThreshold() throws Exception {
|
||||
try (Recording r = new Recording()) {
|
||||
r.enable(EVENT_NAME)
|
||||
.with("filter", CLASS_NAME + "::printHello")
|
||||
.withThreshold(Duration.ofHours(1));
|
||||
r.start();
|
||||
printHello();
|
||||
r.stop();
|
||||
List<RecordedEvent> events = Events.fromRecording(r);
|
||||
if (!events.isEmpty()) {
|
||||
System.out.println(events);
|
||||
throw new Exception("Unexpected MethodTrace event");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void printHello() {
|
||||
System.out.println("Hello!");
|
||||
}
|
||||
|
||||
private static void testWithoutThreshold() throws Exception {
|
||||
AtomicReference<RecordedEvent> o = new AtomicReference<>();
|
||||
AtomicReference<RecordedEvent> i = new AtomicReference<>();
|
||||
AtomicReference<RecordedEvent> e = new AtomicReference<>();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user