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:

  1. Create a shell script that straces a java call:
    strace -f -o lein-strace.out java "$@"
  2. 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:
    {:strace {:java-cmd "/home/timmc/bin/"}}
    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 LEIN_JAVA_CMD and hope it's not quoted properly. :-)
  3. Run your lein command with the new profile overlaid: lein with-profiles +strace run
  4. 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!)

Responses: 1 so far Feed icon

  1. strace’ing a Clojure process under lein « Another Word For It says:

    […] strace’ing a Clojure process under lein by Tim McCormack. […]

Commenting is not yet reimplemented after the Wordpress migration, sorry! For now, you can email me and I can manually add comments.