Created
September 13, 2020 01:03
-
-
Save matthewdowney/bd107177d0db92879da43af156f9b477 to your computer and use it in GitHub Desktop.
Programmatic JVM Thread Dump in Clojure
This file contains hidden or 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
(import '(java.lang.management ManagementFactory)) | |
(defn thread-dump [] | |
(with-out-str | |
(let [tmx-bean (ManagementFactory/getThreadMXBean) | |
tids (.getAllThreadIds tmx-bean) | |
max-stack-depth 100 | |
tinfo (.getThreadInfo tmx-bean tids max-stack-depth)] | |
(doseq [tinf tinfo] | |
(println (str \" (.getThreadName tinf) \")) | |
(println (str " java.lang.Thread.State: " (.getThreadState tinf))) | |
(doseq [ste (.getStackTrace tinf)] | |
(println " at" (str ste))) | |
(println "\n"))))) | |
(comment | |
"Usage" | |
(spit "thread-dump.txt" (thread-dump))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment