I am trying to profile a Java application using DTrace on macOS Sierra 10.12. I am using the 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 Java method entries and exits for specific packages.
DTrace Probes in HotSpot VM and Mac OS X Port Using HotSpot DTrace Probes seem to suggest that this should in fact be supported on macOS. However, even when my Java application is running, there are no hotspot
probes available and jstack()
appears to fail:
⋊> ~ 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
to the dtrace
command does not seem to 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 do I profile a Java application using the DTrace facilities?
You can access the profiling functionality by navigating from the toolbar in Product Class – find Profile As > Java Application. Alternatively, you can use Java’s perspective toolbar using the Profile action. Open your application with the profiling wizard to begin. With profiling, it is vital you identify key parameters to analyze your code.
There are two ways to begin profiling your application. You can access the profiling functionality by navigating from the toolbar in Product Class – find Profile As > Java Application. Alternatively, you can use Java’s perspective toolbar using the Profile action. Open your application with the profiling wizard to begin.
For example, Stackify's Prefix is an excellent lightweight profiling tool, well-suited for profiling not only Java applications but other web applications as well. 7. Conclusion
These code constructs and operations include object creation, iterative executions (including recursive calls), method executions, thread executions, and garbage collections. In this article, we'll be discussing the main Java Profilers: JProfiler, YourKit, Java VisualVM, and the Netbeans Profiler. 2. JProfiler
Well, I was too quick to discount the System Integrity Protection as a possible cause.
After executing csrutil enable --without dtrace
in the Recovery OS (press ⌘R during boot) the hotspot
probes now just show up:
⋊> ~ sudo dtrace -ln 'hotspot*:::' | wc -l
1039
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With