Skip to content

Commit e3f18af

Browse files
committedJun 28, 2023
8311007: jdk/jfr/tool/TestView.java can't find event
Reviewed-by: mgronlun
1 parent 08c51f2 commit e3f18af

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
 

‎test/jdk/jdk/jfr/jcmd/TestJcmdView.java

+25
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323

2424
package jdk.jfr.jcmd;
2525

26+
import java.time.Instant;
2627
import java.util.concurrent.CountDownLatch;
2728

2829
import jdk.jfr.Recording;
30+
import jdk.jfr.consumer.RecordedEvent;
2931
import jdk.jfr.consumer.RecordingStream;
3032
import jdk.test.lib.process.OutputAnalyzer;
3133
/**
@@ -40,6 +42,7 @@
4042
* -XX:+UseG1GC jdk.jfr.jcmd.TestJcmdView
4143
*/
4244
public class TestJcmdView {
45+
private static volatile Instant lastTimestamp;
4346

4447
public static void main(String... args) throws Throwable {
4548
CountDownLatch jvmInformation = new CountDownLatch(1);
@@ -60,22 +63,27 @@ public static void main(String... args) throws Throwable {
6063
rs.onEvent("jdk.JVMInformation", e -> {
6164
jvmInformation.countDown();
6265
System.out.println(e);
66+
storeLastTimestamp(e);
6367
});
6468
rs.onEvent("jdk.SystemGC", e -> {
6569
systemGC.countDown();
6670
System.out.println(e);
71+
storeLastTimestamp(e);
6772
});
6873
rs.onEvent("jdk.GCHeapSummary", e -> {
6974
gcHeapSummary.countDown();
7075
System.out.println(e);
76+
storeLastTimestamp(e);
7177
});
7278
rs.onEvent("jdk.OldGarbageCollection", e -> {
7379
oldCollection.countDown();
7480
System.out.println(e);
81+
storeLastTimestamp(e);
7582
});
7683
rs.onEvent("jdk.GarbageCollection", e-> {
7784
garbageCollection.countDown();
7885
System.out.println(e);
86+
storeLastTimestamp(e);
7987
});
8088
rs.startAsync();
8189
// Emit some GC events
@@ -87,6 +95,16 @@ public static void main(String... args) throws Throwable {
8795
systemGC.await();
8896
gcHeapSummary.await();
8997
oldCollection.countDown();
98+
// Wait for Instant.now() to advance 1 s past the last event timestamp.
99+
// The rationale for this is twofold:
100+
// - DcmdView starts one second before Instant.now() (to make the command
101+
// responsive for the user).
102+
// - Instant.now() and the event timestamp use different time sources
103+
// and they need to synchronize.
104+
Instant end = lastTimestamp.plusSeconds(1);
105+
while (Instant.now().isBefore(end)) {
106+
Thread.sleep(10);
107+
}
90108
// Test events that are in the current chunk
91109
testEventType();
92110
testFormView();
@@ -101,6 +119,13 @@ public static void main(String... args) throws Throwable {
101119
}
102120
}
103121

122+
private static void storeLastTimestamp(RecordedEvent e) {
123+
Instant time = e.getEndTime();
124+
if (lastTimestamp == null || time.isAfter(lastTimestamp)) {
125+
lastTimestamp = time;
126+
}
127+
}
128+
104129
private static void rotate() {
105130
try (Recording r = new Recording()) {
106131
r.start();

0 commit comments

Comments
 (0)
Please sign in to comment.