Profiling tool for Clojure?

11,118

Solution 1

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.

Solution 2

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

Solution 3

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.

Solution 4

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.

Share:
11,118
j-g-faustus
Author by

j-g-faustus

Updated on June 04, 2022

Comments

  • j-g-faustus
    j-g-faustus almost 2 years

    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
    j-g-faustus almost 14 years
    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)?
  • Michał Marczyk
    Michał Marczyk almost 14 years
    There's an SO question on that actually, stackoverflow.com/questions/1892038/… -- 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. ;-)
  • j-g-faustus
    j-g-faustus almost 14 years
    I'll accept your answer :) Not quite what I was looking for, but it seems to be the closest available. Thanks.
  • Xavier Shay
    Xavier Shay over 12 years
    Here is a screencast of how to use VisualVM to get the data you are looking for: rhnh.net/2011/08/03/profiling-clojure
  • Yu Shen
    Yu Shen over 9 years
    This one is obsolete now.
  • Yu Shen
    Yu Shen over 9 years
    I prefer this over VisualVM, as it's light-weight to use and control.
  • Ben Kovitz
    Ben Kovitz almost 8 years
    This seems to provide profiling for ClojureScript only.
  • olieidel
    olieidel about 6 years
    Profiling in timbre has been deprecated, it's now in tufte: github.com/ptaoussanis/tufte