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);
}
}
});
}
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);
}
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;
}
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;
}
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;
}
Aggregations