Search in sources :

Example 21 with RecordedEvent

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();
}
Also used : RecordedEvent(jdk.jfr.consumer.RecordedEvent) Test(org.junit.jupiter.api.Test)

Example 22 with RecordedEvent

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);
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) Config(io.opentelemetry.instrumentation.api.config.Config) RecordedEvent(jdk.jfr.consumer.RecordedEvent) Test(org.junit.jupiter.api.Test)

Example 23 with RecordedEvent

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
}
Also used : Config(io.opentelemetry.instrumentation.api.config.Config) RecordedEvent(jdk.jfr.consumer.RecordedEvent) Test(org.junit.jupiter.api.Test)

Example 24 with RecordedEvent

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;
}
Also used : StackToSpanLinkage(com.splunk.opentelemetry.profiler.context.StackToSpanLinkage) EventType(jdk.jfr.EventType) ArrayList(java.util.ArrayList) RecordedEvent(jdk.jfr.consumer.RecordedEvent)

Example 25 with RecordedEvent

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();
    }
}
Also used : Instant(java.time.Instant) RecordedEvent(jdk.jfr.consumer.RecordedEvent)

Aggregations

RecordedEvent (jdk.jfr.consumer.RecordedEvent)27 Test (org.junit.jupiter.api.Test)14 EventType (jdk.jfr.EventType)11 RecordingFile (jdk.jfr.consumer.RecordingFile)11 Instant (java.time.Instant)5 RecordedThread (jdk.jfr.consumer.RecordedThread)5 Config (io.opentelemetry.instrumentation.api.config.Config)4 File (java.io.File)4 RecordedStackTrace (jdk.jfr.consumer.RecordedStackTrace)4 EventPeriods (com.splunk.opentelemetry.profiler.events.EventPeriods)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 TimeUnit (java.util.concurrent.TimeUnit)3 CONFIG_KEY_MEMORY_SAMPLER_INTERVAL (com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_MEMORY_SAMPLER_INTERVAL)2 CONFIG_KEY_TLAB_ENABLED (com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_TLAB_ENABLED)2 DEFAULT_MEMORY_ENABLED (com.splunk.opentelemetry.profiler.Configuration.DEFAULT_MEMORY_ENABLED)2 DEFAULT_MEMORY_SAMPLING_INTERVAL (com.splunk.opentelemetry.profiler.Configuration.DEFAULT_MEMORY_SAMPLING_INTERVAL)2 SOURCE_EVENT_NAME (com.splunk.opentelemetry.profiler.ProfilingSemanticAttributes.SOURCE_EVENT_NAME)2 SOURCE_TYPE (com.splunk.opentelemetry.profiler.ProfilingSemanticAttributes.SOURCE_TYPE)2 ALLOCATION_SIZE_KEY (com.splunk.opentelemetry.profiler.TLABProcessor.ALLOCATION_SIZE_KEY)2