use of jdk.jfr.consumer.RecordedEvent in project brave by openzipkin.
the class JfrScopeDecoratorTest method endToEndTest.
@Test
public void endToEndTest() throws Exception {
Path destination = folder.newFile("execute.jfr").toPath();
try (Recording recording = new Recording()) {
recording.start();
makeFiveScopes();
recording.dump(destination);
}
List<RecordedEvent> events = RecordingFile.readAllEvents(destination);
assertThat(events).extracting(e -> tuple(e.getString("traceId"), e.getString("parentId"), e.getString("spanId"))).containsExactlyInAnyOrder(tuple("0000000000000001", null, "0000000000000001"), tuple("0000000000000001", null, "0000000000000001"), tuple(null, null, null), tuple("0000000000000001", "0000000000000001", "0000000000000002"), tuple("0000000000000002", null, "0000000000000003"));
}
use of jdk.jfr.consumer.RecordedEvent in project graal by oracle.
the class JfrTest method checkEvents.
protected void checkEvents() {
HashSet<String> seenEvents = new HashSet<>();
try (RecordingFile recordingFile = new RecordingFile(recording.getDestination())) {
while (recordingFile.hasMoreEvents()) {
RecordedEvent event = recordingFile.readEvent();
String eventName = event.getEventType().getName();
seenEvents.add(eventName);
}
} catch (Exception e) {
Assert.fail("Failed to read events: " + e.getMessage());
}
for (String name : getTestedEvents()) {
if (!seenEvents.contains(name)) {
Assert.fail("Event: " + name + " not found in recording");
}
}
}
use of jdk.jfr.consumer.RecordedEvent in project opentelemetry-java-instrumentation by open-telemetry.
the class Analyzer method main.
public static void main(String[] args) throws Exception {
File jfrFile = new File(args[0]);
List<RecordedEvent> events = RecordingFile.readAllEvents(jfrFile.toPath()).stream().filter(e -> e.getEventType().getName().equals("jdk.ExecutionSample")).collect(Collectors.toList());
Set<String> agentCallers = getAgentCallers(events);
for (RecordedEvent event : events) {
totalSamples++;
processStackTrace(event.getStackTrace(), agentCallers);
}
int totalAgentSamples = 0;
for (Node rootNode : syntheticRootNode.getOrderedChildNodes()) {
totalAgentSamples += rootNode.count;
}
System.out.println("Total samples: " + totalSamples);
System.out.print("Total agent samples: " + totalAgentSamples);
System.out.format(" (%.2f%%)%n", 100 * totalAgentSamples / (double) totalSamples);
System.out.println();
for (Node rootNode : syntheticRootNode.getOrderedChildNodes()) {
printNode(rootNode, 0);
}
}
use of jdk.jfr.consumer.RecordedEvent in project cryostat by cryostatio.
the class RecordingWorkflowIT method testWorkflow.
@Test
public void testWorkflow() throws Exception {
// Check preconditions
CompletableFuture<JsonArray> listRespFuture1 = new CompletableFuture<>();
webClient.get(String.format("/api/v1/targets/%s/recordings", TARGET_ID)).send(ar -> {
if (assertRequestStatus(ar, listRespFuture1)) {
listRespFuture1.complete(ar.result().bodyAsJsonArray());
}
});
JsonArray listResp = listRespFuture1.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
Assertions.assertTrue(listResp.isEmpty());
try {
// create an in-memory recording
CompletableFuture<Void> dumpRespFuture = new CompletableFuture<>();
MultiMap form = MultiMap.caseInsensitiveMultiMap();
form.add("recordingName", TEST_RECORDING_NAME);
form.add("duration", "5");
form.add("events", "template=ALL");
webClient.post(String.format("/api/v1/targets/%s/recordings", TARGET_ID)).sendForm(form, ar -> {
if (assertRequestStatus(ar, dumpRespFuture)) {
dumpRespFuture.complete(null);
}
});
dumpRespFuture.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
// verify in-memory recording created
CompletableFuture<JsonArray> listRespFuture2 = new CompletableFuture<>();
webClient.get(String.format("/api/v1/targets/%s/recordings", TARGET_ID)).send(ar -> {
if (assertRequestStatus(ar, listRespFuture2)) {
listRespFuture2.complete(ar.result().bodyAsJsonArray());
}
});
listResp = listRespFuture2.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
MatcherAssert.assertThat("list should have size 1 after recording creation", listResp.size(), Matchers.equalTo(1));
JsonObject recordingInfo = listResp.getJsonObject(0);
MatcherAssert.assertThat(recordingInfo.getString("name"), Matchers.equalTo(TEST_RECORDING_NAME));
MatcherAssert.assertThat(recordingInfo.getString("state"), Matchers.equalTo("RUNNING"));
// wait some time to save a portion of the recording
Thread.sleep(2_000L);
// save a copy of the partial recording dump
CompletableFuture<Void> saveRespFuture = new CompletableFuture<>();
webClient.patch(String.format("/api/v1/targets/%s/recordings/%s", TARGET_ID, TEST_RECORDING_NAME)).sendBuffer(Buffer.buffer("SAVE"), ar -> {
if (assertRequestStatus(ar, saveRespFuture)) {
saveRespFuture.complete(null);
}
});
saveRespFuture.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
// check that the in-memory recording list hasn't changed
CompletableFuture<JsonArray> listRespFuture3 = new CompletableFuture<>();
webClient.get(String.format("/api/v1/targets/%s/recordings", TARGET_ID)).send(ar -> {
if (assertRequestStatus(ar, listRespFuture3)) {
listRespFuture3.complete(ar.result().bodyAsJsonArray());
}
});
listResp = listRespFuture3.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
MatcherAssert.assertThat("list should have size 1 after recording creation", listResp.size(), Matchers.equalTo(1));
recordingInfo = listResp.getJsonObject(0);
MatcherAssert.assertThat(recordingInfo.getString("name"), Matchers.equalTo(TEST_RECORDING_NAME));
MatcherAssert.assertThat(recordingInfo.getString("state"), Matchers.equalTo("RUNNING"));
// verify saved recording created
CompletableFuture<JsonArray> listRespFuture4 = new CompletableFuture<>();
webClient.get("/api/v1/recordings").send(ar -> {
if (assertRequestStatus(ar, listRespFuture4)) {
listRespFuture4.complete(ar.result().bodyAsJsonArray());
}
});
listResp = listRespFuture4.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
MatcherAssert.assertThat("list-saved should have size 1 after recording save", listResp.size(), Matchers.equalTo(1));
recordingInfo = listResp.getJsonObject(0);
MatcherAssert.assertThat(recordingInfo.getString("name"), Matchers.matchesRegex(TARGET_ID + "_" + TEST_RECORDING_NAME + "_[\\d]{8}T[\\d]{6}Z.jfr"));
String savedDownloadUrl = recordingInfo.getString("downloadUrl");
// wait for the dump to complete
Thread.sleep(3_000L);
// verify the in-memory recording list has not changed, except recording is now stopped
CompletableFuture<JsonArray> listRespFuture5 = new CompletableFuture<>();
webClient.get(String.format("/api/v1/targets/%s/recordings", TARGET_ID)).send(ar -> {
if (assertRequestStatus(ar, listRespFuture5)) {
listRespFuture5.complete(ar.result().bodyAsJsonArray());
}
});
listResp = listRespFuture5.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
MatcherAssert.assertThat("list should have size 1 after wait period", listResp.size(), Matchers.equalTo(1));
recordingInfo = listResp.getJsonObject(0);
MatcherAssert.assertThat(recordingInfo.getString("name"), Matchers.equalTo(TEST_RECORDING_NAME));
MatcherAssert.assertThat(recordingInfo.getString("state"), Matchers.equalTo("STOPPED"));
MatcherAssert.assertThat(recordingInfo.getInteger("duration"), Matchers.equalTo(5_000));
// verify in-memory and saved recordings can be downloaded successfully and yield
// non-empty recording binaries containing events, and that
// the fully completed in-memory recording is larger than the saved partial copy
String inMemoryDownloadUrl = recordingInfo.getString("downloadUrl");
Path inMemoryDownloadPath = downloadFileAbs(inMemoryDownloadUrl, TEST_RECORDING_NAME, ".jfr").get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
Path savedDownloadPath = downloadFileAbs(savedDownloadUrl, TEST_RECORDING_NAME + "_saved", ".jfr").get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
MatcherAssert.assertThat(inMemoryDownloadPath.toFile().length(), Matchers.greaterThan(0L));
MatcherAssert.assertThat(savedDownloadPath.toFile().length(), Matchers.greaterThan(0L));
List<RecordedEvent> inMemoryEvents = RecordingFile.readAllEvents(inMemoryDownloadPath);
List<RecordedEvent> savedEvents = RecordingFile.readAllEvents(savedDownloadPath);
MatcherAssert.assertThat(inMemoryEvents.size(), Matchers.greaterThan(savedEvents.size()));
String reportUrl = recordingInfo.getString("reportUrl");
Path reportPath = downloadFileAbs(reportUrl, TEST_RECORDING_NAME + "_report", ".html").get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
File reportFile = reportPath.toFile();
MatcherAssert.assertThat(reportFile.length(), Matchers.greaterThan(0L));
Document doc = Jsoup.parse(reportFile, "UTF-8");
Elements head = doc.getElementsByTag("head");
Elements titles = head.first().getElementsByTag("title");
Elements body = doc.getElementsByTag("body");
Elements script = head.first().getElementsByTag("script");
MatcherAssert.assertThat("Expected one <head>", head.size(), Matchers.equalTo(1));
MatcherAssert.assertThat(titles.size(), Matchers.equalTo(1));
MatcherAssert.assertThat("Expected one <body>", body.size(), Matchers.equalTo(1));
MatcherAssert.assertThat("Expected at least one <script>", script.size(), Matchers.greaterThanOrEqualTo(1));
} finally {
// Clean up what we created
CompletableFuture<Void> deleteRespFuture1 = new CompletableFuture<>();
webClient.delete(String.format("/api/v1/targets/%s/recordings/%s", TARGET_ID, TEST_RECORDING_NAME)).send(ar -> {
if (assertRequestStatus(ar, deleteRespFuture1)) {
deleteRespFuture1.complete(null);
}
});
try {
deleteRespFuture1.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new ITestCleanupFailedException(String.format("Failed to delete target recording %s", TEST_RECORDING_NAME), e);
}
CompletableFuture<JsonArray> savedRecordingsFuture = new CompletableFuture<>();
webClient.get("/api/v1/recordings").send(ar -> {
if (assertRequestStatus(ar, savedRecordingsFuture)) {
savedRecordingsFuture.complete(ar.result().bodyAsJsonArray());
}
});
JsonArray savedRecordings = null;
try {
savedRecordings = savedRecordingsFuture.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new ITestCleanupFailedException("Failed to retrieve archived recordings", e);
}
for (Object savedRecording : savedRecordings) {
String recordingName = ((JsonObject) savedRecording).getString("name");
if (recordingName.matches(TARGET_ID + "_" + TEST_RECORDING_NAME + "_[\\d]{8}T[\\d]{6}Z.jfr")) {
CompletableFuture<Void> deleteRespFuture2 = new CompletableFuture<>();
webClient.delete(String.format("/api/v1/recordings/%s", recordingName)).send(ar -> {
if (assertRequestStatus(ar, deleteRespFuture2)) {
deleteRespFuture2.complete(null);
}
});
try {
deleteRespFuture2.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new ITestCleanupFailedException(String.format("Failed to delete archived recording %s", recordingName), e);
}
}
}
}
}
use of jdk.jfr.consumer.RecordedEvent in project splunk-otel-java by signalfx.
the class EventProcessingChainTest method testFlushOnChunkChange.
@Test
void testFlushOnChunkChange() {
EventProcessingChain chain = new EventProcessingChain(contextualizer, threadDumpProcessor, tlabProcessor);
List<RecordedEvent> events = new ArrayList<>();
EventType contextAttached = newEventType(ContextAttached.EVENT_NAME);
EventType threadDump = newEventType(ThreadDumpProcessor.EVENT_NAME);
// first chunk
for (int i = 0; i < 10; i++) {
events.add(newEvent(contextAttached, Instant.now()));
events.add(newEvent(threadDump, Instant.now()));
}
for (RecordedEvent event : events) {
chain.accept(event);
}
// we have not detected end of chunk so buffer is not flushed yet
verifyNoInteractions(threadDumpProcessor);
verifyNoInteractions(contextualizer);
// create new event types to simulate change of chunk
contextAttached = newEventType(ContextAttached.EVENT_NAME);
threadDump = newEventType(ThreadDumpProcessor.EVENT_NAME);
// second chunk
List<RecordedEvent> events2 = new ArrayList<>();
for (int i = 0; i < 10; i++) {
// context update is the first event that triggers chunk change
events2.add(newEvent(contextAttached, Instant.now()));
events2.add(newEvent(threadDump, Instant.now()));
}
for (RecordedEvent event : events2) {
chain.accept(event);
}
// first chunk was flushed, second chunk is in buffer
verify(contextualizer, times(10)).updateContext(any());
verify(threadDumpProcessor, times(10)).accept(any());
InOrder inOrder = inOrder(threadDumpProcessor, contextualizer);
for (int i = 0; i < 10; i++) {
inOrder.verify(contextualizer).updateContext(events.get(2 * i));
inOrder.verify(threadDumpProcessor).accept(events.get(2 * i + 1));
}
// create new event types to simulate change of chunk
contextAttached = newEventType(ContextAttached.EVENT_NAME);
threadDump = newEventType(ThreadDumpProcessor.EVENT_NAME);
// third chunk
List<RecordedEvent> events3 = new ArrayList<>();
for (int i = 0; i < 10; i++) {
// thread dump is the first event that triggers chunk change
events3.add(newEvent(threadDump, Instant.now()));
events3.add(newEvent(contextAttached, Instant.now()));
}
for (RecordedEvent event : events3) {
chain.accept(event);
}
// second chunk was flushed, third chunk is in buffer
verify(contextualizer, times(20)).updateContext(any());
verify(threadDumpProcessor, times(20)).accept(any());
for (int i = 0; i < 10; i++) {
inOrder.verify(contextualizer).updateContext(events2.get(2 * i));
inOrder.verify(threadDumpProcessor).accept(events2.get(2 * i + 1));
}
// manually flush third chunk
chain.flushBuffer();
verify(contextualizer, times(30)).updateContext(any());
verify(threadDumpProcessor, times(30)).accept(any());
for (int i = 0; i < 10; i++) {
inOrder.verify(threadDumpProcessor).accept(events3.get(2 * i));
inOrder.verify(contextualizer).updateContext(events3.get(2 * i + 1));
}
}
Aggregations