File tree Expand file tree Collapse file tree 6 files changed +13
-17
lines changed
dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap
dd-smoke-tests/profiling-integration-tests/src/test/java/datadog/smoketest
main/java/datadog/trace/util
test/groovy/datadog/trace/util
src/main/java/datadog/trace/util Expand file tree Collapse file tree 6 files changed +13
-17
lines changed Original file line number Diff line number Diff line change @@ -430,8 +430,8 @@ public static void patchJPSAccess(Instrumentation inst) {
430430 // Unclear if supported for J9, may need to revisit
431431 try {
432432 Class .forName ("datadog.trace.util.JPMSJPSAccess" )
433- .getMethod ("patchModuleAccess" )
434- .invoke (inst );
433+ .getMethod ("patchModuleAccess" , Instrumentation . class )
434+ .invoke (null , inst );
435435 } catch (Exception e ) {
436436 log .debug (
437437 SEND_TELEMETRY ,
Original file line number Diff line number Diff line change @@ -507,8 +507,6 @@ void testShutdown(final TestInfo testInfo) throws Exception {
507507 assertTrue (
508508 targetProcess .waitFor (
509509 duration + PROFILING_UPLOAD_TIMEOUT_SECONDS + 1 , TimeUnit .SECONDS ));
510- assertTrue (
511- checkLogLines (logFilePath , it -> it .contains ("Successfully invoked jvmstat" )));
512510 } finally {
513511 if (targetProcess != null ) {
514512 targetProcess .destroyForcibly ();
Original file line number Diff line number Diff line change @@ -41,10 +41,6 @@ forbiddenApisMain {
4141 failOnMissingClasses = false
4242}
4343
44- forbiddenApisMain_java11 {
45- failOnMissingClasses = false
46- }
47-
4844idea {
4945 module {
5046 jdkName = ' 11'
File renamed without changes.
Original file line number Diff line number Diff line change 11package datadog.trace.util
22
33import datadog.trace.test.util.DDSpecification
4+ import net.bytebuddy.agent.ByteBuddyAgent
45
56class PidHelperTest extends DDSpecification {
67
78 def " PID is available everywhere we test" () {
89 expect :
910 ! PidHelper . getPid(). isEmpty()
1011 }
12+
13+ def " JPS via jvmstat is used when possible" () {
14+ when :
15+ def inst = ByteBuddyAgent . install()
16+ JPMSJPSAccess . patchModuleAccess(inst)
17+
18+ then :
19+ JPSUtils.VMPids != null
20+ }
1121}
Original file line number Diff line number Diff line change 22
33import de .thetaphi .forbiddenapis .SuppressForbidden ;
44import java .lang .reflect .Method ;
5- import java .util .HashSet ;
6- import java .util .List ;
75import java .util .Set ;
86import org .slf4j .Logger ;
97import org .slf4j .LoggerFactory ;
@@ -13,21 +11,15 @@ public final class JPSUtils {
1311
1412 @ SuppressForbidden
1513 public static Set <String > getVMPids () {
16- Set <String > vmPids = new HashSet <>();
1714 try {
1815 Class <?> monitoredHostClass = Class .forName ("sun.jvmstat.monitor.MonitoredHost" );
1916 Method getMonitoredHostMethod =
2017 monitoredHostClass .getDeclaredMethod ("getMonitoredHost" , String .class );
2118 Object vmHost = getMonitoredHostMethod .invoke (null , "localhost" );
22- for (Integer vmPid :
23- (List <Integer >) monitoredHostClass .getDeclaredMethod ("activeVms" ).invoke (vmHost )) {
24- vmPids .add (vmPid .toString ());
25- }
26- log .debug ("Successfully invoked jvmstat" );
19+ return (Set <String >) monitoredHostClass .getDeclaredMethod ("activeVms" ).invoke (vmHost );
2720 } catch (Exception e ) {
2821 log .debug ("Failed to invoke jvmstat with exception " , e );
2922 return null ;
3023 }
31- return vmPids ;
3224 }
3325}
You can’t perform that action at this time.
0 commit comments