Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import io.opentelemetry.api.metrics.MeterBuilder;
import io.opentelemetry.instrumentation.api.internal.EmbeddedInstrumentationProperties;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.RecordedEventHandler;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.ThreadGrouper;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.buffer.DirectBufferStatisticsHandler;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.classes.ClassesLoadedHandler;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.container.ContainerConfigurationHandler;
Expand Down Expand Up @@ -84,17 +83,16 @@ static List<RecordedEventHandler> getHandlers(
}
}

ThreadGrouper grouper = new ThreadGrouper();
List<RecordedEventHandler> basicHandlers =
List.of(
new ObjectAllocationInNewTlabHandler(meter, grouper),
new ObjectAllocationOutsideTlabHandler(meter, grouper),
new NetworkReadHandler(meter, grouper),
new NetworkWriteHandler(meter, grouper),
new ObjectAllocationInNewTlabHandler(meter),
new ObjectAllocationOutsideTlabHandler(meter),
new NetworkReadHandler(meter),
new NetworkWriteHandler(meter),
new ContextSwitchRateHandler(meter),
new OverallCpuLoadHandler(meter),
new ContainerConfigurationHandler(meter),
new LongLockHandler(meter, grouper),
new LongLockHandler(meter),
new ThreadCountHandler(meter),
new ClassesLoadedHandler(meter),
new MetaspaceSummaryHandler(meter),
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,35 @@
import io.opentelemetry.api.metrics.DoubleHistogram;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.instrumentation.runtimemetrics.java17.JfrFeature;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.AbstractThreadDispatchingHandler;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.Constants;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.DurationUtil;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.ThreadGrouper;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.RecordedEventHandler;
import java.time.Duration;
import java.util.Optional;
import java.util.function.Consumer;
import jdk.jfr.consumer.RecordedEvent;

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class LongLockHandler extends AbstractThreadDispatchingHandler {
public final class LongLockHandler implements RecordedEventHandler {
private static final String METRIC_NAME = "jvm.cpu.longlock";
private static final String METRIC_DESCRIPTION = "Long lock times";
private static final String EVENT_NAME = "jdk.JavaMonitorWait";

private final DoubleHistogram histogram;
private final Attributes attributes;

public LongLockHandler(Meter meter, ThreadGrouper grouper) {
super(grouper);
public LongLockHandler(Meter meter) {
super();
histogram =
meter
.histogramBuilder(METRIC_NAME)
.setDescription(METRIC_DESCRIPTION)
.setUnit(Constants.SECONDS)
.build();

attributes = Attributes.empty();
}

@Override
Expand All @@ -50,34 +51,17 @@ public JfrFeature getFeature() {
}

@Override
public Consumer<RecordedEvent> createPerThreadSummarizer(String threadName) {
return new PerThreadLongLockHandler(histogram, threadName);
public void accept(RecordedEvent recordedEvent) {
histogram.record(DurationUtil.toSeconds(recordedEvent.getDuration()), attributes);
// What about the class name in MONITOR_CLASS ?
// We can get a stack trace from the thread on the event
// if (recordedEvent.hasField("eventThread")) {
// var eventThread = recordedEvent.getThread("eventThread");
// }
}

@Override
public Optional<Duration> getThreshold() {
return Optional.empty();
}

private static class PerThreadLongLockHandler implements Consumer<RecordedEvent> {
private static final String EVENT_THREAD = "eventThread";

private final DoubleHistogram histogram;
private final Attributes attributes;

public PerThreadLongLockHandler(DoubleHistogram histogram, String threadName) {
this.histogram = histogram;
this.attributes = Attributes.of(Constants.ATTR_THREAD_NAME, threadName);
}

@Override
public void accept(RecordedEvent recordedEvent) {
if (recordedEvent.hasField(EVENT_THREAD)) {
histogram.record(DurationUtil.toSeconds(recordedEvent.getDuration()), attributes);
}
// What about the class name in MONITOR_CLASS ?
// We can get a stack trace from the thread on the event
// var eventThread = recordedEvent.getThread(EVENT_THREAD);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import io.opentelemetry.api.metrics.LongHistogram;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.instrumentation.runtimemetrics.java17.JfrFeature;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.AbstractThreadDispatchingHandler;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.Constants;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.ThreadGrouper;
import java.util.function.Consumer;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.RecordedEventHandler;
import jdk.jfr.consumer.RecordedEvent;

/**
Expand All @@ -22,20 +20,23 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public final class ObjectAllocationInNewTlabHandler extends AbstractThreadDispatchingHandler {
public final class ObjectAllocationInNewTlabHandler implements RecordedEventHandler {
private static final String EVENT_NAME = "jdk.ObjectAllocationInNewTLAB";
private static final String TLAB_SIZE = "tlabSize";

private final LongHistogram histogram;
private final Attributes attributes;

public ObjectAllocationInNewTlabHandler(Meter meter, ThreadGrouper grouper) {
super(grouper);
public ObjectAllocationInNewTlabHandler(Meter meter) {
super();
histogram =
meter
.histogramBuilder(Constants.METRIC_NAME_MEMORY_ALLOCATION)
.setDescription(Constants.METRIC_DESCRIPTION_MEMORY_ALLOCATION)
.setUnit(Constants.BYTES)
.ofLongs()
.build();
attributes = Attributes.of(Constants.ATTR_ARENA_NAME, "TLAB");
}

@Override
Expand All @@ -49,29 +50,9 @@ public JfrFeature getFeature() {
}

@Override
public Consumer<RecordedEvent> createPerThreadSummarizer(String threadName) {
return new PerThreadObjectAllocationInNewTlabHandler(histogram, threadName);
}

/** This class aggregates all TLAB allocation JFR events for a single thread */
private static class PerThreadObjectAllocationInNewTlabHandler
implements Consumer<RecordedEvent> {
private static final String TLAB_SIZE = "tlabSize";

private final LongHistogram histogram;
private final Attributes attributes;

public PerThreadObjectAllocationInNewTlabHandler(LongHistogram histogram, String threadName) {
this.histogram = histogram;
this.attributes =
Attributes.of(Constants.ATTR_THREAD_NAME, threadName, Constants.ATTR_ARENA_NAME, "TLAB");
}

@Override
public void accept(RecordedEvent ev) {
histogram.record(ev.getLong(TLAB_SIZE), attributes);
// Probably too high a cardinality
// ev.getClass("objectClass").getName();
}
public void accept(RecordedEvent ev) {
histogram.record(ev.getLong(TLAB_SIZE), attributes);
// Probably too high a cardinality
// ev.getClass("objectClass").getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import io.opentelemetry.api.metrics.LongHistogram;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.instrumentation.runtimemetrics.java17.JfrFeature;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.AbstractThreadDispatchingHandler;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.Constants;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.ThreadGrouper;
import java.util.function.Consumer;
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.RecordedEventHandler;
import jdk.jfr.consumer.RecordedEvent;

/**
Expand All @@ -22,20 +20,24 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public final class ObjectAllocationOutsideTlabHandler extends AbstractThreadDispatchingHandler {
public final class ObjectAllocationOutsideTlabHandler implements RecordedEventHandler {
private static final String EVENT_NAME = "jdk.ObjectAllocationOutsideTLAB";
private static final String ALLOCATION_SIZE = "allocationSize";

private final LongHistogram histogram;
private final Attributes attributes;

public ObjectAllocationOutsideTlabHandler(Meter meter, ThreadGrouper grouper) {
super(grouper);
public ObjectAllocationOutsideTlabHandler(Meter meter) {
super();
histogram =
meter
.histogramBuilder(Constants.METRIC_NAME_MEMORY_ALLOCATION)
.setDescription(Constants.METRIC_DESCRIPTION_MEMORY_ALLOCATION)
.setUnit(Constants.BYTES)
.ofLongs()
.build();

attributes = Attributes.of(Constants.ATTR_ARENA_NAME, "Main");
}

@Override
Expand All @@ -49,29 +51,9 @@ public JfrFeature getFeature() {
}

@Override
public Consumer<RecordedEvent> createPerThreadSummarizer(String threadName) {
return new PerThreadObjectAllocationOutsideTlabHandler(histogram, threadName);
}

/** This class aggregates all non-TLAB allocation JFR events for a single thread */
private static class PerThreadObjectAllocationOutsideTlabHandler
implements Consumer<RecordedEvent> {
private static final String ALLOCATION_SIZE = "allocationSize";

private final LongHistogram histogram;
private final Attributes attributes;

public PerThreadObjectAllocationOutsideTlabHandler(LongHistogram histogram, String threadName) {
this.histogram = histogram;
this.attributes =
Attributes.of(Constants.ATTR_THREAD_NAME, threadName, Constants.ATTR_ARENA_NAME, "Main");
}

@Override
public void accept(RecordedEvent ev) {
histogram.record(ev.getLong(ALLOCATION_SIZE), attributes);
// Probably too high a cardinality
// ev.getClass("objectClass").getName();
}
public void accept(RecordedEvent ev) {
histogram.record(ev.getLong(ALLOCATION_SIZE), attributes);
// Probably too high a cardinality
// ev.getClass("objectClass").getName();
}
}
Loading
Loading