views:

196

answers:

2

Hi,

does anyone know of a good profiling tool or library for Clojure?

I would prefer something that could be used from the REPL, along the lines of (with-profiling ...) in Allegro Common Lisp back in the day.

Is there anything along those lines?

Or do you have any experience with (non-commercial) Java profilers that work well with Clojure?

+4  A: 

I found VisualVM (see here and here) to be very convenient. Its use with Clojure has been described about a year ago in this blog post; as far as I can see, it's not outdated in any way.

Note that the GUI from which one starts the VisualVM profiler has a prominent text area where one can enter classes / packages to be excluded from profiling -- I find the results rather more useful when clojure.* is on that list.

Michał Marczyk
Thanks for the pointer. The monitor part - heap memory and CPU usage - is handy. But I'm struggling with getting anything useful from the CPU profiler. Profiling a solution to a Project Euler problem, the top contributor from my code is 300ms out of several minutes runtime... Is there anything that gives method "total time" (time spent on call stack) rather than "self time" (time spent on top of call stack)?
j-g-faustus
There's an SO question on that actually, http://stackoverflow.com/questions/1892038/total-method-time-in-java-visualvm -- the advice to take a snapshot of the profiling results and analyse that is good, that gives you a nice "call tree" view with total method times included. One more thing to keep in mind is that this is one place where single-segment namespaces can be a problem (AFAICT that was the cause of some functions being "invisible" in a recent profiling session I conducted together with Licenser in #clojure), though I won't promise they will break things in your particular case. ;-)
Michał Marczyk
I'll accept your answer :) Not quite what I was looking for, but it seems to be the closest available. Thanks.
j-g-faustus
You're welcome, I wish I knew something closer to what you wanted...
Michał Marczyk
+1  A: 

Just found profile in Clojure contrib.

It doesn't work for large amounts of code (it blew up with OutOfMemoryError on a Project Euler solution which VisualVM handled just fine) and it requires you to insert profiling calls in the functions you want to profile.

Still, it's a better alternative to VisualVM in the cases where you just want to profile a couple of functions.

j-g-faustus