Skip to content

Instantly share code, notes, and snippets.

@Hendekagon Hendekagon/deps.edn
Last active Jun 12, 2019

Embed
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
([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))))))))
@Hendekagon

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:

(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

:profiling
    {
       :extra-deps
       {
                    profile-ns         {:git/url "https://gist.github.com/Hendekagon/75139bb285ccd8cc183fe69415ccc66f" 
                                              :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.