Profiling Java applications with DTrace on macOS

I am trying to profile a Java application using DTrace on macOS Sierra 10.12. I am using JDK8:

โ‹Š> ~ java -version java version "1.8.0_102" Java(TM) SE Runtime Environment (build 1.8.0_102-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode) โ‹Š> ~ echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home 

My ultimate goal is to trace all the entries and outputs of the Java method for specific packages.

DTrace Probes on the HotSpot VM and Mac OS X Port using HotSpot DTrace Probes seem to suggest that this should actually be supported on macOS. However, even when my Java application is running, there are no hotspot probes available and jstack() crashes:

 โ‹Š> ~ pgrep java 24564 โ‹Š> ~ sudo dtrace -ln 'hotspot*:::' dtrace: system integrity protection is on, some features will not be available ID PROVIDER MODULE FUNCTION NAME dtrace: failed to match hotspot*:::: No probe matches description โ‹Š> ~ sudo dtrace -n 'syscall::read:entry /execname == "java"/ { jstack(); }' dtrace: system integrity protection is on, some features will not be available dtrace: description 'syscall::read:entry ' matched 1 probe dtrace: error on enabled probe ID 1 (ID 153: syscall::read:entry): invalid address (0xe2e3275e) in action #1 dtrace: error on enabled probe ID 1 (ID 153: syscall::read:entry): invalid address (0xe2e3275e) in action #1 dtrace: error on enabled probe ID 1 (ID 153: syscall::read:entry): invalid address (0xe2e3275e) in action #1 โ€ฆ 

Providing the path to libjvm.dylib with the libjvm.dylib command dtrace not help:

 โ‹Š> ~ ll "$JAVA_HOME/jre/lib/server/" total 31616 -rw-rw-r-- 1 root wheel 1.4K Jun 22 15:02 Xusage.txt -rwxrwxr-x 1 root wheel 15K Jun 22 15:01 libjsig.dylib -rwxrwxr-x 1 root wheel 15M Jun 22 15:02 libjvm.dylib โ‹Š> ~ sudo dtrace -L "$JAVA_HOME/jre/lib/server/" -ln 'hotspot*:::' dtrace: system integrity protection is on, some features will not be available ID PROVIDER MODULE FUNCTION NAME dtrace: failed to match hotspot*:::: No probe matches description 

So what am I missing? How to profile a Java application using DTrace tools?

+5
source share
1 answer

Well, I was too fast to minimize system integrity protection as a possible reason.

After running csrutil enable --without dtrace in the recovery OS (press โŒ˜R during boot), hotspot probes will now appear:

 โ‹Š> ~ sudo dtrace -ln 'hotspot*:::' | wc -l 1039 
+5
source

Source: https://habr.com/ru/post/1258777/


All Articles