Last active
July 30, 2022 15:50
-
-
Save DayoOliyide/f353b15563675120e408b6b9f504628a to your computer and use it in GitHub Desktop.
Get all thread information in clojure
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
(defn print-threads [& {:keys [headers pre-fn] | |
:or {pre-fn identity}}] | |
(let [thread-set (keys (Thread/getAllStackTraces)) | |
thread-data (mapv bean thread-set) | |
headers (or headers (-> thread-data first keys))] | |
(clojure.pprint/print-table headers (pre-fn thread-data)))) | |
(defn print-threads-str [& args] | |
(with-out-str (apply print-threads args))) | |
(comment | |
;;print all properties for all threads | |
(print-threads) | |
;;print name,state,alive,daemon properties for all threads | |
(print-threads :headers [:name :state :alive :daemon]) | |
;;print name,state,alive,daemon properties for non-daemon threads | |
(print-threads :headers [:name :state :alive :daemon] :pre-fn (partial filter #(false? (:daemon %)))) | |
;;log name,state,alive,daemon properties for non-daemon threads | |
(log/debug (print-threads-str :headers [:name :state :alive :daemon] :pre-fn (partial filter #(false? (:daemon %))))) | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment