Skip to content

Commit 1c33702

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

File tree

1 file changed

+45
-14
lines changed

1 file changed

+45
-14
lines changed

src/taoensso/tufte.cljc

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -313,20 +313,51 @@
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+
;; @TODO What about xfns
334+
335+
(if elide?
336+
(do ~@body)
337+
(let [{dynamic? :dynamic?
338+
nmax-form :nmax
339+
id-form :id
340+
level-form :level
341+
sample-form :sample
342+
data-form :data} opts]
343+
344+
`((fn [] ; iife for better IoC compatibility
345+
(let [;; handlers# impl/*sig-handlers*
346+
body-fn# (fn [] ~@body)
347+
~'__ns ~ns-form
348+
~'__id ~id-form
349+
~'__level ~level-form]
350+
351+
(enc/if-not (enc/and? #_handlers# ~allow?)
352+
(body-fn#)
353+
(let [;; inst# (enc/now-inst)
354+
[body-result# pstats#] (profiled* 'tufte/profiled ~dynamic? ~nmax-form (body-fn#))]
355+
(when pstats#
356+
(impl/handle!
357+
(HandlerVal. ~ns-form ~level-form ~id-form ~data-form
358+
pstats# (delay (format-pstats pstats#))
359+
~*file* ~(:line (meta &form)))))
360+
body-result#))))))))))
330361

331362
(comment (profile {:id ::my-id} (p :p1 "body")))
332363

0 commit comments

Comments
 (0)