use of jdk.jfr.consumer.RecordedEvent in project splunk-otel-java by signalfx.
the class BasicJfrRecordingFileTest method testOpen.
@Test
void testOpen() throws Exception {
RecordedEvent e1 = mock(RecordedEvent.class);
RecordedEvent e2 = mock(RecordedEvent.class);
RecordedEvent e3 = mock(RecordedEvent.class);
when(recordingFile.hasMoreEvents()).thenReturn(true, true, true, false);
when(jfr.openRecordingFile(path)).thenReturn(recordingFile);
when(jfr.readEvent(recordingFile, path)).thenReturn(e1, e2, e3);
BasicJfrRecordingFile basicJfrRecordingFile = new BasicJfrRecordingFile(jfr);
Stream<RecordedEvent> stream = basicJfrRecordingFile.open(path);
List<RecordedEvent> result = stream.collect(Collectors.toList());
List<RecordedEvent> expected = Arrays.asList(e1, e2, e3);
assertEquals(expected, result);
verify(recordingFile).close();
}
use of jdk.jfr.consumer.RecordedEvent in project splunk-otel-java by signalfx.
the class TLABProcessorTest method testProfilingDisabled.
@Test
void testProfilingDisabled() {
RecordedEvent event = mock(RecordedEvent.class, new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
throw new IllegalStateException("RecordedEvent methods should not be called when TLAB profiling is not enabled");
}
});
Config config = mock(Config.class);
when(config.getBoolean(CONFIG_KEY_TLAB_ENABLED, DEFAULT_MEMORY_ENABLED)).thenReturn(false);
TLABProcessor processor = TLABProcessor.builder(config).build();
processor.accept(event);
}
use of jdk.jfr.consumer.RecordedEvent in project splunk-otel-java by signalfx.
the class TLABProcessorTest method testNullStack.
@Test
void testNullStack() {
RecordedEvent event = mock(RecordedEvent.class);
// just to be explicit
when(event.getStackTrace()).thenReturn(null);
Config config = mock(Config.class);
when(config.getBoolean(CONFIG_KEY_TLAB_ENABLED, DEFAULT_MEMORY_ENABLED)).thenReturn(true);
TLABProcessor processor = TLABProcessor.builder(config).build();
processor.accept(event);
// success, no NPEs
}
use of jdk.jfr.consumer.RecordedEvent in project splunk-otel-java by signalfx.
the class ThreadDumpProcessorTest method collectResults.
private static List<StackToSpanLinkage> collectResults(SpanContextualizer contextualizer, String threadDump, boolean onlyTracingSpans) {
List<StackToSpanLinkage> results = new ArrayList<>();
Consumer<StackToSpanLinkage> exportProcessor = results::add;
ThreadDumpProcessor processor = ThreadDumpProcessor.builder().spanContextualizer(contextualizer).processor(exportProcessor).stackTraceFilter(new StackTraceFilter(false)).onlyTracingSpans(onlyTracingSpans).build();
RecordedEvent event = mock(RecordedEvent.class);
EventType eventType = mock(EventType.class);
when(event.getEventType()).thenReturn(eventType);
when(eventType.getName()).thenReturn(ThreadDumpProcessor.EVENT_NAME);
when(event.getString("result")).thenReturn(threadDump);
processor.accept(event);
return results;
}
use of jdk.jfr.consumer.RecordedEvent in project splunk-otel-java by signalfx.
the class JfrPathHandler method accept.
@Override
public void accept(Path path) {
logger.info("New jfr file detected: {} size: {}", path, path.toFile().length());
Instant start = Instant.now();
try {
RecordedEventStream recordingFile = recordedEventStreamFactory.get();
try (Stream<RecordedEvent> events = recordingFile.open(path)) {
events.forEach(eventProcessingChain::accept);
}
eventProcessingChain.flushBuffer();
onFileFinished.accept(path);
} finally {
Instant end = Instant.now();
long timeElapsed = Duration.between(start, end).toMillis();
logger.debug("Processed {} in {}ms", path, timeElapsed);
eventProcessingChain.logEventStats();
}
}
Aggregations