-
-
Save refset/5d1e80c2044e25db9355e6f7a7b46f13 to your computer and use it in GitHub Desktop.
Repl fns to generate a flame graph. (Not super sophisticated!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Assumes https://github.com/jstepien/flames available | |
;; requires http://riemann.io to be installed. | |
(def flames (atom nil)) | |
(defn flames-start! [] | |
;; We resolve explicitly here, to avoid warnings when not working | |
;; with flamegraphs | |
(if-not @flames | |
(let [config {:port 54321, :host "localhost"}] | |
(reset! flames ((requiring-resolve 'flames.core/start!) config)) | |
(printf "You must have http://riemann.io profiler installed.\nView flames graph at http://%s:%d/flames.svg\n" (:host config) (:port config))) | |
(throw (IllegalStateException. "Stop the existing capture first!")))) | |
(defn flames-stop! [] | |
;; We resolve explicitly here, to avoid warnings when not working | |
;; with flamegraphs | |
(when @flames | |
(reset! flames ((requiring-resolve 'flames.core/stop!) @flames)))) | |
(defmacro flames-do | |
" | |
Just like (do ...) but capturing a flamegraph whilst executing the body. | |
(flames-do | |
(f arg1 arg2) | |
(g arg3 arg4)) | |
" | |
[& body] | |
`(with-open [_# (flames-start!)] | |
~@body | |
(println "Capture Flame graph now:\ncurl -sO http://localhost:54321/flames.svg\n\nThen press ENTER") | |
(read-line) | |
nil)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment