mirror of
https://github.com/status-im/timbre.git
synced 2025-01-30 21:57:08 +00:00
profiling: add defnp
macro
This commit is contained in:
parent
afd8a87b11
commit
1157a0e97c
@ -1,7 +1,8 @@
|
|||||||
(ns taoensso.timbre.profiling
|
(ns taoensso.timbre.profiling
|
||||||
"Logging profiler for Timbre, adapted from clojure.contrib.profile."
|
"Logging profiler for Timbre, adapted from clojure.contrib.profile."
|
||||||
{:author "Peter Taoussanis"}
|
{:author "Peter Taoussanis"}
|
||||||
(:require [taoensso.timbre :as timbre]
|
(:require [clojure.tools.macro :as macro]
|
||||||
|
[taoensso.timbre :as timbre]
|
||||||
[taoensso.timbre.utils :as utils]))
|
[taoensso.timbre.utils :as utils]))
|
||||||
|
|
||||||
(def ^:dynamic *pdata* "{::pname [time1 time2 ...]}" nil)
|
(def ^:dynamic *pdata* "{::pname [time1 time2 ...]}" nil)
|
||||||
@ -114,6 +115,20 @@
|
|||||||
(printf s-pattern "Accounted Time" "" "" "" "" ""
|
(printf s-pattern "Accounted Time" "" "" "" "" ""
|
||||||
(perc accounted clock-time) (ft accounted)))))
|
(perc accounted clock-time) (ft accounted)))))
|
||||||
|
|
||||||
|
(defmacro defnp "Like `defn` but wraps body in `p` macro."
|
||||||
|
{:arglists '([name doc-string? attr-map? [params] prepost-map? body])}
|
||||||
|
[name & sigs]
|
||||||
|
(let [[name more] (macro/name-with-attributes name sigs)
|
||||||
|
body (last more)
|
||||||
|
more (butlast more)]
|
||||||
|
`(defn ~name ~@more
|
||||||
|
(p ~(clojure.core/name name)
|
||||||
|
~body))))
|
||||||
|
|
||||||
|
(comment (defnp foo "Docstring "[x] (* x x))
|
||||||
|
(macroexpand '(defnp foo "Docstring "[x] (* x x)))
|
||||||
|
(profile :info :defnp-test (foo 5)))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(profile :info :Sleepy-threads
|
(profile :info :Sleepy-threads
|
||||||
(dotimes [n 5]
|
(dotimes [n 5]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user