41

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?

j-g-faustus
  • 8,801
  • 4
  • 32
  • 42

4 Answers4

29

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
  • 83,634
  • 13
  • 201
  • 212
  • 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 Jun 05 '10 at 00:20
  • 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 Jun 05 '10 at 01:44
  • I'll accept your answer :) Not quite what I was looking for, but it seems to be the closest available. Thanks. – j-g-faustus Jun 07 '10 at 20:52
  • 1
    Here is a screencast of how to use VisualVM to get the data you are looking for: http://rhnh.net/2011/08/03/profiling-clojure – Xavier Shay Aug 03 '11 at 10:49
15

There's a newish Clojure library which offers profiling: https://github.com/ptaoussanis/timbre

higginbotham
  • 1,879
  • 4
  • 16
  • 14
10

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
  • 8,801
  • 4
  • 32
  • 42
10

Quick heads-up that I've deprecated Timbre's profiling for a new dedicated Clojure + ClojureScript profiling lib at https://github.com/ptaoussanis/tufte.

That's basically a refinement of the stuff from Timbre, plus dedicated docs.

The README includes a comparison with JVM tools like VisualVM, YourKit, etc.