Skip to content

Instantly share code, notes, and snippets.

@camsaul
Created March 3, 2020 23:54
Show Gist options
  • Save camsaul/4c6d0dc9f9bce520be951bdcdd1a91b0 to your computer and use it in GitHub Desktop.
Save camsaul/4c6d0dc9f9bce520be951bdcdd1a91b0 to your computer and use it in GitHub Desktop.
Print all threads grouped by pattern
(defn- all-threads []
(transduce
identity
(fn
([]
{})
([m]
(into (flatland.ordered.map/ordered-map)
(cons
[:total (reduce + (vals m))]
(sort-by #(- (second %)) m))))
([m ^Thread thread]
(let [thread-name (clojure.string/replace (.getName thread) #"\d+" "")]
(update m thread-name (fnil inc 0)))))
(keys (Thread/getAllStackTraces))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment