Runtime call stack tracing and terminal tree visualization for Clojure code.
Use with-trace around code that calls trace-call, deftraced, or
deftracedmacro. The resulting trace is plain EDN and can be rendered with
trace->text or trace->return-text.
Runtime call stack tracing and terminal tree visualization for Clojure code. Use `with-trace` around code that calls `trace-call`, `deftraced`, or `deftracedmacro`. The resulting trace is plain EDN and can be rendered with `trace->text` or `trace->return-text`.
Atom containing the active trace while with-trace is executing.
Atom containing the active trace while `with-trace` is executing.
(current-trace)Returns the current public trace map, or an empty trace when tracing is off.
Returns the current public trace map, or an empty trace when tracing is off.
(deftraced fn-name & fdecl)Defines a fixed-arity traced function.
The declaration follows defn for docstrings, metadata, pre/post maps, and
one or more fixed arities. Variadic functions can still be traced by wrapping
individual calls with trace-call.
Defines a fixed-arity traced function. The declaration follows `defn` for docstrings, metadata, pre/post maps, and one or more fixed arities. Variadic functions can still be traced by wrapping individual calls with `trace-call`.
(deftracedmacro macro-name params & body)Defines a macro whose expanded runtime body appears as a :macro frame.
Macro arguments are shown as source forms because macros receive syntax, not evaluated values.
Defines a macro whose expanded runtime body appears as a `:macro` frame. Macro arguments are shown as source forms because macros receive syntax, not evaluated values.
(enter! frame)Adds a running frame to the active trace and returns the frame id.
Adds a running frame to the active trace and returns the frame id.
(finish! frame-id outcome)Completes frame-id in the active trace with outcome.
Completes `frame-id` in the active trace with `outcome`.
(print-return-trace trace)(print-return-trace trace options)Prints trace as a leaf-to-root return flow and returns nil.
Options are the same as trace->return-text.
Prints `trace` as a leaf-to-root return flow and returns nil. Options are the same as `trace->return-text`.
(print-trace trace)(print-trace trace options)Prints trace as a terminal tree and returns nil.
Options are the same as trace->text.
Prints `trace` as a terminal tree and returns nil. Options are the same as `trace->text`.
(run-frame kind name args thunk)Runs zero-argument thunk inside a traced frame.
kind is usually :function or :macro, name is the display name, and
args are the values or source forms to show in the graph.
Runs zero-argument `thunk` inside a traced frame. `kind` is usually `:function` or `:macro`, `name` is the display name, and `args` are the values or source forms to show in the graph.
(trace->return-text trace)(trace->return-text trace options)Renders trace as a leaf-to-root return flow string.
This view is useful for seeing how recursive leaf results recombine into
parent return values. Options may include :style (:unicode or :ascii).
Renders `trace` as a leaf-to-root return flow string. This view is useful for seeing how recursive leaf results recombine into parent return values. Options may include `:style` (`:unicode` or `:ascii`).
(trace->text trace)(trace->text trace options)Renders trace as a terminal tree string.
Options may include :style (:unicode or :ascii) and :show-meta?.
Renders `trace` as a terminal tree string. Options may include `:style` (`:unicode` or `:ascii`) and `:show-meta?`.
(trace-call f & args)Traces a single function call and labels the node as (f arg1 arg2 ..).
Traces a single function call and labels the node as `(f arg1 arg2 ..)`.
(tracing?)Returns true when callgraph is currently collecting trace frames.
Returns true when callgraph is currently collecting trace frames.
(with-trace & body)Evaluates body with tracing enabled.
Returns {:result value :trace trace-map} when body returns normally. When
body throws, the original exception is rethrown with the partial trace in
(ex-data exception) under :callgraph/trace.
Evaluates `body` with tracing enabled.
Returns `{:result value :trace trace-map}` when `body` returns normally. When
`body` throws, the original exception is rethrown with the partial trace in
`(ex-data exception)` under `:callgraph/trace`.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |