Dsxir.Trace (dsxir v0.1.0)

Copy Markdown

Process-local trace accumulator for Dsxir.with_trace/1.

Owns a single process-dict slot. When the slot is nil, record/1 is a no-op. Inference paths (no with_trace) pay one Process.get/1 per Dsxir.Module.Runtime.call/4 and allocate nothing.

The slot does not cross process boundaries. Dsxir.Predictor.Parallel, Dsxir.Evaluate, and any user-spawned task run with their own nil slot. Bootstrap optimization is single-process by design.

Entries are pushed on the head ([entry | acc]) and reversed on stop/1, so callers see them in forward order.

Summary

Functions

True iff a with_trace block is currently open in this process.

Append an entry. No-op when no with_trace is active.

Open a fresh accumulator. Returns the prior slot value for stop/1.

Close the accumulator, restore the prior slot, and return the trace.

Types

entry()

@type entry() ::
  {atom(), map(), Dsxir.Prediction.t(), [Dsxir.Demo.t() | Dsxir.Example.t()]}

Functions

active?()

@spec active?() :: boolean()

True iff a with_trace block is currently open in this process.

record(entry)

@spec record(entry()) :: :ok

Append an entry. No-op when no with_trace is active.

start()

@spec start() :: nil | [entry()]

Open a fresh accumulator. Returns the prior slot value for stop/1.

stop(prior)

@spec stop(nil | [entry()]) :: [entry()]

Close the accumulator, restore the prior slot, and return the trace.