35
35
import jdk .test .lib .Asserts ;
36
36
import jdk .test .lib .jfr .EventNames ;
37
37
38
- // Java agent that emits in multiple threads
38
+ // Java agent that emits events
39
39
public class EventEmitterAgent {
40
40
41
- private static final int THREADS = 5 ;
42
- private static final int EVENTS_PER_THREAD = 150_000 ;
43
- private static final int EXPECTED_COUNT = THREADS * EVENTS_PER_THREAD ;
41
+ private static final long EVENTS = 150_000 ;
44
42
private static final Path DUMP_PATH = Paths .get ("dump.jfr" ).toAbsolutePath ();
45
43
46
44
// Called when agent is loaded from command line
@@ -58,20 +56,13 @@ private static void agentWork() throws Exception {
58
56
r .enable (EventNames .JavaExceptionThrow );
59
57
r .setDestination (DUMP_PATH );
60
58
r .start ();
61
- Thread [] threads = new Thread [THREADS ];
62
- for (int i = 0 ; i < THREADS ; i ++) {
63
- threads [i ] = new Thread (EventEmitterAgent ::emitEvents );
64
- threads [i ].start ();
65
- }
66
- for (int i = 0 ; i < THREADS ; i ++) {
67
- threads [i ].join ();
68
- }
59
+ emitEvents ();
69
60
r .stop ();
70
61
}
71
62
}
72
63
73
64
public static void emitEvents () {
74
- for (int i = 0 ; i < EVENTS_PER_THREAD ; i ++) {
65
+ for (int i = 0 ; i < EVENTS ; i ++) {
75
66
TestEvent e = new TestEvent ();
76
67
e .msg = "Long message that puts pressure on the string pool " + i % 100 ;
77
68
e .count = i ;
@@ -80,7 +71,7 @@ public static void emitEvents() {
80
71
e .commit ();
81
72
if (i % 10000 == 0 ) {
82
73
try {
83
- Thread .sleep (1 );
74
+ Thread .sleep (10 );
84
75
} catch (InterruptedException ie ) {
85
76
// ignore
86
77
}
@@ -101,6 +92,6 @@ public static void validateRecording() throws Exception {
101
92
.stream ()
102
93
.filter (e -> e .getEventType ().getName ().equals ("Test" ))
103
94
.count ();
104
- Asserts .assertTrue (testEventCount == EXPECTED_COUNT , "Mismatch in TestEvent count" );
95
+ Asserts .assertEquals (testEventCount , EVENTS , "Mismatch in TestEvent count" );
105
96
}
106
97
}
0 commit comments