Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-999.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Delegate to the jvm-diagnostics library for safepoint time access
links:
- https://github.com/palantir/tritium/pull/999
1 change: 1 addition & 0 deletions tritium-metrics-jvm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies {
api 'io.dropwizard.metrics:metrics-core'

implementation project(':tritium-metrics')
implementation 'com.palantir.jvm.diagnostics:jvm-diagnostics'
implementation 'io.dropwizard.metrics:metrics-core'
implementation 'io.dropwizard.metrics:metrics-jvm'
implementation 'com.google.guava:guava'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package com.palantir.tritium.metrics.jvm;

import com.codahale.metrics.Gauge;
import com.palantir.jvm.diagnostics.JvmDiagnostics;
import com.palantir.jvm.diagnostics.SafepointTimeAccessor;
import com.palantir.tritium.metrics.registry.TaggedMetricRegistry;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -31,27 +31,12 @@
final class SafepointMetrics {
private static final Logger log = LoggerFactory.getLogger(SafepointMetrics.class);

// The reflection is so that we can use this on non-Hotspot JVMs
@SuppressWarnings("LiteralClassName")
static void register(TaggedMetricRegistry registry) {
try {
Class<?> managementFactoryHelper = Class.forName("sun.management.ManagementFactoryHelper");
Method getHotspotRuntimeMBean = managementFactoryHelper.getMethod("getHotspotRuntimeMBean");
Object hotspotRuntimeMBean = getHotspotRuntimeMBean.invoke(null);
Method getTotalSafepointTime = hotspotRuntimeMBean.getClass().getMethod("getTotalSafepointTime");
getTotalSafepointTime.setAccessible(true);
Gauge<Long> gauge = () -> (Long) invoke(getTotalSafepointTime, hotspotRuntimeMBean);
InternalJvmMetrics.of(registry).safepointTime(gauge);
} catch (ReflectiveOperationException e) {
log.info("Could not get the total safepoint time, these metrics will not be registered.", e);
}
}

private static Object invoke(Method method, Object object) {
try {
return method.invoke(object);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException(e);
Optional<SafepointTimeAccessor> safepointTimeAccessor = JvmDiagnostics.totalSafepointTime();
if (safepointTimeAccessor.isPresent()) {
InternalJvmMetrics.of(registry).safepointTime(safepointTimeAccessor.get()::safepointTimeMilliseconds);
} else {
log.info("Could not get the total safepoint time, these metrics will not be registered.");
}
}

Expand Down
3 changes: 2 additions & 1 deletion versions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ com.google.guava:failureaccess:1.0.1 (1 constraints: 140ae1b4)
com.google.guava:guava:30.1-jre (6 constraints: be5513ea)
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918)
com.google.j2objc:j2objc-annotations:1.3 (1 constraints: b809eda0)
com.palantir.jvm.diagnostics:jvm-diagnostics:0.0.1 (1 constraints: 0305ec35)
com.palantir.remoting-api:tracing:1.9.0 (1 constraints: 520d0e26)
com.palantir.remoting3:jackson-support:3.46.0 (1 constraints: 850d9c33)
com.palantir.remoting3:tracing:3.46.0 (1 constraints: 3f05533b)
Expand All @@ -30,7 +31,7 @@ org.checkerframework:checker-qual:3.10.0 (3 constraints: 4b1f441d)
org.hdrhistogram:HdrHistogram:2.1.12 (1 constraints: 3805313b)
org.immutables:value:2.8.8 (1 constraints: 14051536)
org.mpierce.metrics.reservoir:hdrhistogram-metrics-reservoir:1.1.2 (1 constraints: 0605f535)
org.slf4j:slf4j-api:1.7.30 (6 constraints: ca470ac6)
org.slf4j:slf4j-api:1.7.30 (7 constraints: f15ab3d6)

[Test dependencies]
com.squareup.okhttp3:okhttp:4.0.0 (1 constraints: 0605ff35)
Expand Down
1 change: 1 addition & 0 deletions versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ com.google.code.findbugs:jFormatString = 3.0.0
com.google.code.findbugs:jsr305 = 3.0.2
com.google.errorprone:* = 2.5.1
com.google.guava:guava = 30.1-jre
com.palantir.jvm.diagnostics:* = 0.0.1
com.palantir.remoting3:* = 3.46.0
com.palantir.safe-logging:* = 1.14.0
com.palantir.tracing:* = 4.11.0
Expand Down