|
313 | 313 |
|
314 | 314 | [opts & body]
|
315 | 315 | (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#)))))))))) |
330 | 361 |
|
331 | 362 | (comment (profile {:id ::my-id} (p :p1 "body")))
|
332 | 363 |
|
|
0 commit comments