Search in sources :

Example 1 with EventType

use of jdk.jfr.EventType in project btrace by btraceio.

the class BTraceFunctionalTests method testJfr.

@Test
public void testJfr() throws Exception {
    String rtVersion = System.getProperty("java.runtime.version", "");
    String testJavaHome = System.getenv().get("TEST_JAVA_HOME");
    if (testJavaHome != null) {
        Properties releaseProps = new Properties();
        releaseProps.load(new FileInputStream(new File(testJavaHome + File.separator + "release")));
        rtVersion = releaseProps.getProperty("JAVA_VERSION").replace("\"", "");
    }
    if (!rtVersion.startsWith("15.")) {
        // skip the test for 8.0.* because of missing support
        // skip all non-LTS versions (except the last one)
        // skip the test for JDK 11 since the latest version 11.0.9 and newer ends in SISGSEGV
        System.err.println("Skipping test for JDK " + rtVersion);
        return;
    }
    testWithJfr("resources.Main", "btrace/JfrTest.java", 10, new ResultValidator() {

        @Override
        public void validate(String stdout, String stderr, int retcode, String jfrFile) {
            assertFalse(stdout.contains("FAILED"), "Script should not have failed");
            assertTrue(stderr.isEmpty(), "Non-empty stderr");
            assertNotNull(jfrFile);
            try {
                RecordingFile f = new RecordingFile(Paths.get(jfrFile));
                boolean hasPeriodicType = false, hasPeriodicValue = false, hasCustomType = false, hasCustomValue = false;
                for (EventType et : f.readEventTypes()) {
                    if (et.getName().equals("periodic")) {
                        hasPeriodicType = true;
                    } else if (et.getName().equals("custom")) {
                        hasCustomType = true;
                    }
                    if (hasPeriodicType && hasCustomType) {
                        while (f.hasMoreEvents()) {
                            RecordedEvent e = f.readEvent();
                            if (e.getEventType().getName().equals("periodic")) {
                                hasPeriodicValue = true;
                            } else if (e.getEventType().getName().equals("custom")) {
                                hasCustomValue = true;
                            }
                            if (hasPeriodicValue && hasCustomValue) {
                                return;
                            }
                        }
                        break;
                    }
                }
                fail("periodic type ok: " + hasPeriodicType + ", periodic value ok: " + hasPeriodicValue + ", custom type ok: " + hasCustomType + ", custom value ok: " + hasCustomValue);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
}
Also used : EventType(jdk.jfr.EventType) RecordedEvent(jdk.jfr.consumer.RecordedEvent) RecordingFile(jdk.jfr.consumer.RecordingFile) IOException(java.io.IOException) Properties(java.util.Properties) RecordingFile(jdk.jfr.consumer.RecordingFile) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.jupiter.api.Test)

Example 2 with EventType

use of jdk.jfr.EventType in project splunk-otel-java by signalfx.

the class LogDataCommonAttributesTest method testBuild.

@Test
void testBuild() {
    String sourceType = "otel.profiling";
    String eventName = "core.core.unicorn";
    Attributes expected = Attributes.builder().put(SOURCE_TYPE, sourceType).put(SOURCE_EVENT_NAME, eventName).put(SOURCE_EVENT_PERIOD, 999L).build();
    EventPeriods periods = mock(EventPeriods.class);
    RecordedEvent event = mock(RecordedEvent.class);
    EventType eventType = mock(EventType.class);
    when(event.getEventType()).thenReturn(eventType);
    when(eventType.getName()).thenReturn(eventName);
    when(periods.getDuration(eventName)).thenReturn(Duration.ofMillis(999));
    LogDataCommonAttributes logDataAttributes = new LogDataCommonAttributes(periods);
    Attributes result = logDataAttributes.builder(event.getEventType().getName()).build();
    assertEquals(expected, result);
}
Also used : EventPeriods(com.splunk.opentelemetry.profiler.events.EventPeriods) EventType(jdk.jfr.EventType) Attributes(io.opentelemetry.api.common.Attributes) RecordedEvent(jdk.jfr.consumer.RecordedEvent) Test(org.junit.jupiter.api.Test)

Example 3 with EventType

use of jdk.jfr.EventType in project splunk-otel-java by signalfx.

the class TLABProcessorTest method createMockEvent.

private RecordedEvent createMockEvent(StackSerializer serializer, Instant now, Long tlabSize) {
    String stackAsString = "i am a serialized stack believe me";
    RecordedEvent event = mock(RecordedEvent.class);
    RecordedStackTrace stack = mock(RecordedStackTrace.class);
    EventType eventType = mock(EventType.class);
    RecordedThread mockThread = mock(RecordedThread.class);
    when(event.getStartTime()).thenReturn(now);
    when(event.getStackTrace()).thenReturn(stack);
    when(event.getEventType()).thenReturn(eventType);
    when(event.getLong("allocationSize")).thenReturn(ONE_MB);
    when(event.getThread()).thenReturn(mockThread);
    when(mockThread.getJavaThreadId()).thenReturn(THREAD_ID);
    when(mockThread.getJavaName()).thenReturn("mockingbird");
    when(event.hasField("tlabSize")).thenReturn(tlabSize != null);
    if (tlabSize == null) {
        when(event.getLong("tlabSize")).thenThrow(NullPointerException.class);
    } else {
        when(event.getLong("tlabSize")).thenReturn(tlabSize);
    }
    when(eventType.getName()).thenReturn("tee-lab");
    when(serializer.serialize(stack)).thenReturn(stackAsString);
    return event;
}
Also used : EventType(jdk.jfr.EventType) RecordedEvent(jdk.jfr.consumer.RecordedEvent) RecordedStackTrace(jdk.jfr.consumer.RecordedStackTrace) RecordedThread(jdk.jfr.consumer.RecordedThread)

Example 4 with EventType

use of jdk.jfr.EventType in project splunk-otel-java by signalfx.

the class ThreadDumpProcessorTest method threadContextStartEvent.

private static RecordedEvent threadContextStartEvent(long threadId) {
    RecordedEvent event = mock(RecordedEvent.class);
    EventType type = mock(EventType.class);
    when(type.getName()).thenReturn(ContextAttached.EVENT_NAME);
    when(event.getEventType()).thenReturn(type);
    when(event.getString("traceId")).thenReturn(traceId);
    when(event.getString("spanId")).thenReturn(spanId);
    when(event.getByte("traceFlags")).thenReturn(traceFlags);
    RecordedThread thread = mock(RecordedThread.class);
    when(thread.getJavaThreadId()).thenReturn(threadId);
    when(event.getThread()).thenReturn(thread);
    return event;
}
Also used : EventType(jdk.jfr.EventType) RecordedEvent(jdk.jfr.consumer.RecordedEvent) RecordedThread(jdk.jfr.consumer.RecordedThread)

Example 5 with EventType

use of jdk.jfr.EventType in project splunk-otel-java by signalfx.

the class SpanContextualizerTest method buildEvents.

private Events buildEvents(String spanId, long threadId, Events parent) {
    Events result = new Events(spanId, threadId);
    result.scopeStart = contextEventIn(spanId, threadId);
    result.scopeEnd = contextEventOut(parent, threadId);
    result.sourceEvent = mock(RecordedEvent.class);
    EventType eventType = mock(EventType.class);
    when(result.sourceEvent.getEventType()).thenReturn(eventType);
    when(eventType.getName()).thenReturn("GreatSourceEventHere");
    return result;
}
Also used : EventType(jdk.jfr.EventType) RecordedEvent(jdk.jfr.consumer.RecordedEvent)

Aggregations

EventType (jdk.jfr.EventType)13 RecordedEvent (jdk.jfr.consumer.RecordedEvent)11 Test (org.junit.jupiter.api.Test)5 RecordedThread (jdk.jfr.consumer.RecordedThread)3 InOrder (org.mockito.InOrder)3 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 StackToSpanLinkage (com.splunk.opentelemetry.profiler.context.StackToSpanLinkage)1 EventPeriods (com.splunk.opentelemetry.profiler.events.EventPeriods)1 Attributes (io.opentelemetry.api.common.Attributes)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 RecordedStackTrace (jdk.jfr.consumer.RecordedStackTrace)1 RecordingFile (jdk.jfr.consumer.RecordingFile)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1