Getting Dtraceasm profiler to work with JMH on macOS
Patrick Concannon
patrick.concannon at oracle.com
Fri Feb 28 12:21:38 UTC 2020
Hi,
It seems the Dtraceasm profiler does not work with JMH on macOS, and a
couple of hacks are needed in order to get it working consistently. I
spoke to Paul Sandoz about this issue, and he was able to provide me
with the workaround described below.
When using dtraceasm, a dtrace process is executed that samples the
program counter of processes, and the sampling results are then streamed
to a file. The first issue is that the output file is not getting
updated with samples when JMH kills the dtrace process.
Paul provided the small patch (below) that explicitly sends a signal to
the sudo process to make sure dtrace spits out the required results. He
mentioned that this might be something to do with the Java
implementation of Process.destroy.
diff -r 1a48e97d9dea
jmh-core/src/main/java/org/openjdk/jmh/profile/DTraceAsmProfiler.java
---
a/jmh-core/src/main/java/org/openjdk/jmh/profile/DTraceAsmProfiler.java
Fri Feb 14 09:42:04 2020 +0100
+++
b/jmh-core/src/main/java/org/openjdk/jmh/profile/DTraceAsmProfiler.java
Mon Feb 24 12:20:48 2020 -0800
@@ -87,6 +87,9 @@
throw new IllegalStateException("DTrace needs the forked
VM PID, but it is not initialized");
}
+ long dtracePid = dtraceProcess.pid();
+ Utils.tryWith("sudo", "kill", "-15", Long.toString(dtracePid));
+
Collection<String> messages = Utils.destroy(dtraceProcess);
if (!messages.isEmpty()) {
throw new IllegalStateException(messages.toString());
As well as applying the patch above, you also have to ensure the hsdis
library is preloaded when running the JVM. The easiest way to ensure
this is to place it in the current directory. This avoids the pain of
breaking out of the mac sandbox for preloading libraries. This issue was
previously discussed here:
http://mail.openjdk.java.net/pipermail/jmh-dev/2018-January/002686.html.
While the solution above works, it is not ideal. I wanted to send this
email to the list to see if there was any interest in possibly finding a
more permanent solution to this?
Kind regards,
Patrick
More information about the jmh-dev
mailing list