profile all functions in a namespace
(ns profile-ns | |
(:require [taoensso.tufte :as tufte :refer [p]] | |
[robert.hooke :as hooke])) | |
(defn profile-ns | |
([namespace-name] | |
(profile-ns {:enable true} namespace-name)) | |
([{profile? :enable} namespace-name] | |
(doseq [[_ v] | |
(filter | |
(fn [[_ x]] | |
(if (and (var? x) (fn? @x)) (-> x meta :ns ns-name #{namespace-name}) false)) | |
(ns-map namespace-name))] | |
(hooke/remove-hook v :p) | |
(when profile? | |
(hooke/add-hook v :p | |
(fn [f & args] | |
(p (keyword (name namespace-name) (name (:name (meta v)))) | |
(apply f args)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Hendekagon commentedMay 15, 2019
•
edited
You want to profile all functions in a namespace, this uses Tufte and Robert Hooke to make that so:
(profile-ns 'my-name-space)
(tufte/format-pstats @(last (profiled {} (my-function))))
profile-ns
all the namespaces to the level of detail you want to be included in the results(profile-ns {:enable false} 'my-name-space)
to disable profiling from a namespace