Skip to content

Commit

Permalink
Add debug logging when diagnostics cannot be loaded (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
carterkozak authored Feb 22, 2021
1 parent 1a16d0b commit e735e96
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-12.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Add debug logging when diagnostics cannot be loaded
links:
- https://github.com/palantir/jvm-diagnostics/pull/12
6 changes: 4 additions & 2 deletions jvm-diagnostics/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
apply from: "$rootDir/gradle/publish-jar.gradle"

dependencies {
// No main dependencies
// Minimal main dependencies
implementation 'org.slf4j:slf4j-api'

testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.assertj:assertj-core'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.palantir.jvm.diagnostics;

import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This utility class provides accessors to individual diagnostic getters. Every method should
Expand All @@ -25,20 +27,27 @@
*/
public final class JvmDiagnostics {

private static final Logger log = LoggerFactory.getLogger(JvmDiagnostics.class);

/**
* Returns an {@link SafepointTimeAccessor} which provides safepoint information. This functionality
* is not supported on all java runtimes, and an {@link Optional#empty()} is returned in cases
* safepoint data is unavailable.
*
* The resulting instance should be reused rather than calling this factory each time a
* value is needed.
*
* Currently this supports up to java 16 assuming {@code --illegal-access=deny} is not used, and java 17+
* only when the {@code --illegal-access=permit} paramter is provided. Once a safe, suitable replacement is
* found, we will likely use a multi-release jar to leverage the new functionality.
*/
public static Optional<SafepointTimeAccessor> totalSafepointTime() {
try {
// Classes used by HotspotSafepointTimeAccessor are not guaranteed to exist at runtime on all JREs
// so we must fail gracefully.
return Optional.of(new HotspotSafepointTimeAccessor());
} catch (Throwable t) {
log.debug("Failed to create a HotspotSafepointTimeAccessor", t);
return Optional.empty();
}
}
Expand Down
1 change: 1 addition & 0 deletions versions.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Run ./gradlew --write-locks to regenerate this file
org.slf4j:slf4j-api:1.7.30 (1 constraints: 3d05453b)

[Test dependencies]
org.apiguardian:apiguardian-api:1.1.0 (5 constraints: 0654a8a8)
Expand Down
1 change: 1 addition & 0 deletions versions.props
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.slf4j:* = 1.7.30
org.junit.jupiter:* = 5.7.1
org.assertj:assertj-core = 3.19.0

0 comments on commit e735e96

Please sign in to comment.