Skip to content

Instantly share code, notes, and snippets.

@Hendekagon Hendekagon/deps.edn
Last active Dec 23, 2019

What would you like to do?
profile all functions in a namespace
{:paths ["."] :deps {robert/hooke {:mvn/version "1.3.0"}
com.taoensso/tufte {:mvn/version "2.0.1"}}}
(ns profile-ns
(:require [taoensso.tufte :as tufte :refer [p]]
[robert.hooke :as hooke]))
(defn profile-ns
(profile-ns {:enable true} namespace-name))
([{profile? :enable} namespace-name]
(doseq [[_ v]
(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))))))))

This comment has been minimized.

Copy link
Owner Author

Hendekagon commented May 15, 2019

You want to profile all functions in a namespace, this uses Tufte and Robert Hooke to make that so:

(use 'profile-ns)
(require '[taoensso.tufte :as tufte])

(profile-ns 'my-name-space)
(tufte/format-pstats @(last (tufte/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

          profile-ns {:git/url "" 
                            :sha "347094bf0fafb51c7d4bb1362646e35cc3efe8c6"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.