Skip to content

Commit 4391b2b

Browse files
committed
[nop] Custom profile expansion
Prep for switching from `HandlerVal` to `PSignal` content, and new (signal toolkit) handler dispatch.
1 parent 3c6085e commit 4391b2b

File tree

1 file changed

+43
-14
lines changed

1 file changed

+43
-14
lines changed

src/taoensso/tufte.cljc

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -313,20 +313,49 @@
313313

314314
[opts & body]
315315
(impl/valid-opts! &form &env 'tufte/profile opts body)
316-
(let [opts (merge {:level 5} opts)
317-
ns-form* (get opts :ns :auto)
318-
ns-form (auto-> ns-form* (str *ns*))
319-
level-form (get opts :level)
320-
id-form (get opts :id)
321-
data-form (get opts :data)]
322-
323-
`(let [[result# pstats#] (profiled ~opts ~@body)]
324-
(when pstats#
325-
(impl/handle!
326-
(HandlerVal. ~ns-form ~level-form ~id-form ~data-form
327-
pstats# (delay (format-pstats pstats#))
328-
~*file* ~(:line (meta &form)))))
329-
result#))))
316+
(let [opts (merge {:level 5} opts)
317+
ns-form* (get opts :ns :auto)
318+
ns-form (auto-> ns-form* (str *ns*))
319+
320+
{:keys [elide? allow?]}
321+
(sigs/filter-call
322+
{:cljs? (boolean (:ns &env))
323+
:sf-arity 3
324+
:ct-call-filter impl/ct-call-filter
325+
:*rt-call-filter* `impl/*rt-call-filter*}
326+
(assoc opts
327+
:ns ns-form
328+
:local-forms
329+
{:ns '__ns
330+
:id '__id
331+
:level '__level}))]
332+
333+
(if elide?
334+
(do ~@body)
335+
(let [{dynamic? :dynamic?
336+
nmax-form :nmax
337+
id-form :id
338+
level-form :level
339+
sample-form :sample
340+
data-form :data} opts]
341+
342+
`((fn [] ; iife for better IoC compatibility
343+
(let [;; handlers# impl/*sig-handlers*
344+
body-fn# (fn [] ~@body)
345+
~'__ns ~ns-form
346+
~'__id ~id-form
347+
~'__level ~level-form]
348+
349+
(enc/if-not (enc/and? #_handlers# ~allow?)
350+
(body-fn#)
351+
(let [;; inst# (enc/now-inst)
352+
[body-result# pstats#] (profiled* 'tufte/profiled ~dynamic? ~nmax-form (body-fn#))]
353+
(when pstats#
354+
(impl/handle!
355+
(HandlerVal. ~ns-form ~level-form ~id-form ~data-form
356+
pstats# (delay (format-pstats pstats#))
357+
~*file* ~(:line (meta &form)))))
358+
body-result#))))))))))
330359

331360
(comment (profile {:id ::my-id} (p :p1 "body")))
332361

0 commit comments

Comments
 (0)