strace’ing a Clojure process under lein
Today I wanted to strace a JVM process to see if it was making network calls, and I discovered a minor roadblock: It was a Clojure program being run using the Leiningen build tool. lein run
spawns a JVM subprocess and then exits, and I only wanted to trace that subprocess.
The solution is simple, but worth a post: Tell lein to run a different "java" command that actually wraps a call to java with strace. Here's how I did it:
- Create a shell script that straces a java call:
#!/bin/bash strace -f -o lein-strace.out java "$@"
- Add a
strace
profile to~/.lein/profiles.clj
to call that instead of java directly. If you don't have any profiles already, the file might end up looking like this:
Note that this changes the invocation for the subprocess; if you wanted to change the JVM used for running lein itself, you'd want to look into{:strace {:java-cmd "/home/timmc/bin/strace-java.sh"}}
LEIN_JAVA_CMD
and hope it's not quoted properly. :-) - Run your lein command with the new profile overlaid:
lein with-profiles +strace run
- Grovel through
lein-strace.out
in the current directory and see what turned up!
Thanks to ridcully in the #clojure IRC channel on freenode for reminding me to use the -f
option (trace forked subprocesses too!)
strace’ing a Clojure process under lein « Another Word For It says:
[…] strace’ing a Clojure process under lein by Tim McCormack. […]