Skip to content
Permalink
Browse files
8250903: jdk/jfr/javaagent/TestLoadedAgent.java fails with Mismatch i…
…n TestEvent count

Reviewed-by: mgronlun
  • Loading branch information
egahlin committed Jan 7, 2021
1 parent 4f914e2 commit 4a478b8a98d00e1a5cda589e528a73135e783a5e
Showing 1 changed file with 6 additions and 15 deletions.
@@ -35,12 +35,10 @@
import jdk.test.lib.Asserts;
import jdk.test.lib.jfr.EventNames;

// Java agent that emits in multiple threads
// Java agent that emits events
public class EventEmitterAgent {

private static final int THREADS = 5;
private static final int EVENTS_PER_THREAD = 150_000;
private static final int EXPECTED_COUNT = THREADS * EVENTS_PER_THREAD;
private static final long EVENTS = 150_000;
private static final Path DUMP_PATH = Paths.get("dump.jfr").toAbsolutePath();

// Called when agent is loaded from command line
@@ -58,20 +56,13 @@ private static void agentWork() throws Exception {
r.enable(EventNames.JavaExceptionThrow);
r.setDestination(DUMP_PATH);
r.start();
Thread[] threads = new Thread[THREADS];
for (int i = 0; i < THREADS; i++) {
threads[i] = new Thread(EventEmitterAgent::emitEvents);
threads[i].start();
}
for (int i = 0; i < THREADS; i++) {
threads[i].join();
}
emitEvents();
r.stop();
}
}

public static void emitEvents() {
for (int i = 0; i < EVENTS_PER_THREAD; i++) {
for (int i = 0; i < EVENTS; i++) {
TestEvent e = new TestEvent();
e.msg = "Long message that puts pressure on the string pool " + i % 100;
e.count = i;
@@ -80,7 +71,7 @@ public static void emitEvents() {
e.commit();
if (i % 10000 == 0) {
try {
Thread.sleep(1);
Thread.sleep(10);
} catch (InterruptedException ie) {
// ignore
}
@@ -101,6 +92,6 @@ public static void validateRecording() throws Exception {
.stream()
.filter(e -> e.getEventType().getName().equals("Test"))
.count();
Asserts.assertTrue(testEventCount == EXPECTED_COUNT, "Mismatch in TestEvent count");
Asserts.assertEquals(testEventCount, EVENTS, "Mismatch in TestEvent count");
}
}

0 comments on commit 4a478b8

Please sign in to comment.