Profile Clojure Step by Step
Profile in CodeScene with async-profiler:
-
Check that the following is set to 1:
cat /proc/sys/kernel/perf_event_paranoid
-
To set it do this:
echo 1 | sudo tee /proc/sys/kernel/perf_event_paranoid
-
Add the following to your project.clj (if you’re using leinigen):
:async-profiler {:jvm-opts ["-Djdk.attach.allowAttachSelf" "-XX:+UnlockDiagnosticVMOptions" "-XX:+DebugNonSafepoints"]
:dependencies [[com.clojure-goes-fast/clj-async-profiler "1.0.0-alpha1"]]}
- Require the profiler in your ns, and add
(proc/profile)
around the interesting code
(require '[clj-async-profiler.core :as prof])
;; Profile your expression:
(prof/profile (dotimes [i 10000] (reduce + (range i))))
- Inspect the result:
- The resulting flamegraph will be stored in
/tmp/clj-async-profiler/results/
- You can view the SVG directly from there or start a local webserver:
(prof/serve-files 8080)