Skip to content

Commit 4bc86a2

Browse files
committed
8367948: JFR: MethodTrace threshold setting has no effect
Reviewed-by: shade
1 parent 02c78bb commit 4bc86a2

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

src/jdk.jfr/share/classes/jdk/jfr/events/MethodTraceEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static long timestamp() {
4949
return 0;
5050
}
5151

52-
public static boolean enabled() {
52+
public static boolean shouldCommit(long duration) {
5353
// Generated by JFR
5454
return false;
5555
}

src/jdk.jfr/share/classes/jdk/jfr/tracing/MethodTracer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static long timestamp() {
5050
public static void traceObjectInit(long startTime, long methodId) {
5151
long endTime = JVM.counterTime();
5252
long duration = endTime - startTime;
53-
if (MethodTraceEvent.enabled() && JVM.getEventWriter() != null) {
53+
if (MethodTraceEvent.shouldCommit(duration) && JVM.getEventWriter() != null) {
5454
MethodTraceEvent.commit(startTime, duration, methodId);
5555
}
5656
}
@@ -66,7 +66,7 @@ public static void timingObjectInit(long startTime, long methodId) {
6666
public static void traceTimingObjectInit(long startTime, long methodId) {
6767
long endTime = JVM.counterTime();
6868
long duration = endTime - startTime;
69-
if (MethodTraceEvent.enabled() && JVM.getEventWriter() != null) {
69+
if (MethodTraceEvent.shouldCommit(duration) && JVM.getEventWriter() != null) {
7070
MethodTraceEvent.commit(startTime, duration, methodId);
7171
}
7272
if (MethodTimingEvent.enabled()) {
@@ -77,7 +77,7 @@ public static void traceTimingObjectInit(long startTime, long methodId) {
7777
public static void trace(long startTime, long methodId) {
7878
long endTime = JVM.counterTime();
7979
long duration = endTime - startTime;
80-
if (MethodTraceEvent.enabled()) {
80+
if (MethodTraceEvent.shouldCommit(duration)) {
8181
MethodTraceEvent.commit(startTime, duration, methodId);
8282
}
8383
}
@@ -96,7 +96,7 @@ public static void traceTiming(long startTime, long methodId) {
9696
if (MethodTimingEvent.enabled()) {
9797
PlatformTracer.addTiming(methodId, duration);
9898
}
99-
if (MethodTraceEvent.enabled()) {
99+
if (MethodTraceEvent.shouldCommit(duration)) {
100100
MethodTraceEvent.commit(startTime, duration, methodId);
101101
}
102102
}

test/jdk/jdk/jfr/event/tracing/TestMethodTrace.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@
2222
*/
2323
package jdk.jfr.event.tracing;
2424

25+
import java.time.Duration;
26+
import java.util.List;
2527
import java.util.concurrent.atomic.AtomicReference;
2628

2729
import jdk.jfr.Event;
2830
import jdk.jfr.StackTrace;
2931
import jdk.jfr.consumer.RecordedEvent;
3032
import jdk.jfr.consumer.RecordedMethod;
3133
import jdk.jfr.consumer.RecordingStream;
34+
import jdk.jfr.Recording;
3235

36+
import jdk.test.lib.jfr.Events;
3337
/**
3438
* @test
3539
* @summary Basic test of the MethodTrace event.
@@ -52,6 +56,31 @@ private static class InnerMeasurement extends Event {
5256
}
5357

5458
public static void main(String... args) throws Exception {
59+
testWithoutThreshold();
60+
testWithThreshold();
61+
}
62+
63+
private static void testWithThreshold() throws Exception {
64+
try (Recording r = new Recording()) {
65+
r.enable(EVENT_NAME)
66+
.with("filter", CLASS_NAME + "::printHello")
67+
.withThreshold(Duration.ofHours(1));
68+
r.start();
69+
printHello();
70+
r.stop();
71+
List<RecordedEvent> events = Events.fromRecording(r);
72+
if (!events.isEmpty()) {
73+
System.out.println(events);
74+
throw new Exception("Unexpected MethodTrace event");
75+
}
76+
}
77+
}
78+
79+
public static void printHello() {
80+
System.out.println("Hello!");
81+
}
82+
83+
private static void testWithoutThreshold() throws Exception {
5584
AtomicReference<RecordedEvent> o = new AtomicReference<>();
5685
AtomicReference<RecordedEvent> i = new AtomicReference<>();
5786
AtomicReference<RecordedEvent> e = new AtomicReference<>();

0 commit comments

Comments
 (0)