Issues with dtraceasm, and a workaround
Paul Sandoz
paul.sandoz at oracle.com
Mon Jan 25 17:16:53 UTC 2021
Hi,
Numerous Mac users are having issues with dtraceasm. This may be complicated by SIP, although I have it enabled and can get dtraceasm to work.
Digging a little deeper I observed that the dtrace process does not like being destroyed (as in Process.destroy()) by the Java process.
Some dtrace output is initially present in the output file (tailing the file). When the dtrace process is destroyed it returns an error code of 141, and no further output is present in the output file. I believe error code 141 is associated with the dtrace process receiving a SIGPIPE signal.
Sending a TERM signal before destroying the process works around this issue (see patch below). It kicks the dtrace process, resulting in the process relinquishing the remaining dtrace output to the output file.
I don’t know why this works, but perhaps this information and the workaround will help others work out what is going on, so a proper fix can be proposed?
Paul.
diff --git a/jmh-core/src/main/java/org/openjdk/jmh/profile/DTraceAsmProfiler.java b/jmh-core/src/main/java/org/openjdk/jmh/profile/DTraceAsmProfiler.java
index 34f67941..0d6fba58 100644
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/DTraceAsmProfiler.java
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/DTraceAsmProfiler.java
@@ -87,6 +87,9 @@ public class DTraceAsmProfiler extends AbstractPerfAsmProfiler {
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());
diff --git a/jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java b/jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java
index fc8c10c7..1ee0db4f 100644
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java
@@ -488,6 +488,7 @@ public class Utils {
return Collections.emptyList();
}
+ messages.add("DTrace exit code: " + exitCode);
messages.add(baos.toString());
return messages;
} catch (InterruptedException e) {
More information about the jmh-dev
mailing list