-
Notifications
You must be signed in to change notification settings - Fork 304
Use jvmstat for JDKs 9+ programmatically #8641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bfe5a1f
Expose & use jvmstat for JDK 9+ programmatically
MattAlp e5a415f
Revert unnecessary dependency on JDK 11 for profiling tests
MattAlp 1a50268
Merge branch 'master' into mattalp/patch-jvmstat-access
MattAlp 388e646
Send telemetry about jvmstat / jps usage
MattAlp 627d36b
Merge branch 'mattalp/patch-jvmstat-access' of github.com:DataDog/dd-…
MattAlp 62e3ee8
Address internal inconsistency & test instability
MattAlp c8a3b02
Merge branch 'master' into mattalp/patch-jvmstat-access
MattAlp 2893834
Retrieve unnamed module via platform class loader
MattAlp c4a8bdc
Merge branch 'mattalp/patch-jvmstat-access' of github.com:DataDog/dd-…
MattAlp 2ead3b7
Use system class loader for 17+ JDK support
MattAlp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
internal-api/internal-api-9/src/main_java11/java/datadog/trace/util/JPMSJPSAccess.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package datadog.trace.util; | ||
|
||
import java.lang.instrument.Instrumentation; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class JPMSJPSAccess { | ||
public static void patchModuleAccess(Instrumentation inst) { | ||
Module unnamedModule = JPMSJPSAccess.class.getClassLoader().getUnnamedModule(); | ||
Module jvmstatModule = ModuleLayer.boot().findModule("jdk.internal.jvmstat").orElse(null); | ||
|
||
if (jvmstatModule != null) { | ||
Map<String, Set<Module>> extraOpens = Map.of("sun.jvmstat.monitor", Set.of(unnamedModule)); | ||
|
||
// Redefine the module | ||
inst.redefineModule( | ||
jvmstatModule, | ||
Collections.emptySet(), | ||
extraOpens, | ||
extraOpens, | ||
Collections.emptySet(), | ||
Collections.emptyMap()); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
internal-api/src/main/java/datadog/trace/util/JPSUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package datadog.trace.util; | ||
|
||
import de.thetaphi.forbiddenapis.SuppressForbidden; | ||
import java.lang.reflect.Method; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public final class JPSUtils { | ||
private static final Logger log = LoggerFactory.getLogger(JPSUtils.class); | ||
|
||
@SuppressForbidden | ||
public static Set<String> getVMPids() { | ||
Set<String> vmPids = new HashSet<>(); | ||
try { | ||
Class<?> monitoredHostClass = Class.forName("sun.jvmstat.monitor.MonitoredHost"); | ||
Method getMonitoredHostMethod = | ||
monitoredHostClass.getDeclaredMethod("getMonitoredHost", String.class); | ||
Object vmHost = getMonitoredHostMethod.invoke(null, "localhost"); | ||
for (Integer vmPid : | ||
(List<Integer>) monitoredHostClass.getDeclaredMethod("activeVms").invoke(vmHost)) { | ||
vmPids.add(vmPid.toString()); | ||
} | ||
log.debug("Successfully invoked jvmstat"); | ||
} catch (Exception e) { | ||
log.debug("Failed to invoke jvmstat with exception ", e); | ||
return null; | ||
} | ||
return vmPids; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.