code wiki / (root) / nx_trace.nx

nx_trace.nx

buildroot/runtime/nx_trace.nx

6367 B170 linesdepth 4pulls 4 transitivereach 0 importersview sourcekind tooltopic trace
docsdependenciesstructsconstsfunctions

about

nx_trace.nx -- span-based tracing. Structured call-tree observability. When a function enters + exits, emit a pair of span events with matching IDs, so offline analysis can reconstruct the exact call path and timing profile. Design draws from: OpenTelemetry tracing data model -- span id, parent id, start/end, attributes Google Dapper (Sigelman et al 2010) -- distributed tracing origin paper Rust tracing crate -- in-process span primitives Linux ftrace -- kernel-mode per-function trace perf probe -- USDT tracepoints Span events are emitted through nx_log, so all existing level/tag/filter infrastructure applies. Format: <seq> DEBUG span.enter <tag> id=<N> parent=<P> <seq> DEBUG span.exit <tag> id=<N> dt=<elapsed_ticks> Matching pairs reconstruct the tree off-line via seq ordering. `dt` is a monotonic tick counter the tracer maintains (NOT wall-clock, by design -- reproducible across runs). Not yet (deferred): * rdtime CSR read for real wall-clock nanoseconds. Needs inline asm in NishiLang, which we don't have yet. When it lands, dt gets real ns units. * Sampling -- limit overhead by only tracing every N calls. * Remote export -- emit spans to a socket in OTLP / Zipkin protobuf format for external analyzers. Span IDs are monotonic per-context. Parent id = id of the enclosing span, or 0 for root spans. For single-threaded v0.0.1 we track a stack of active span ids. When threading arrives, per-thread span stacks + flush-on-thread-join are the pattern.

dependencies 2 imports · 0 importers

syscalls.nx nx_log.nx nx_trace.nx

imports: syscalls.nxnx_log.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_log_new nx_trace_new nx_span_enter nx_log_emit ipow10 nx_log_puts nx_log_level_name nx_log_puti nx_span_exit nx_log_emit ↻ nx_log_puti ↻

structs

51struct NxTraceCtx

consts

49const NX_TRACE_STACK_DEPTH: i64 = 64
59const NX_TRACE_CTX_BYTES: i64 = 48

functions

63func nx_trace_new(log: *NxLogContext) -> *NxTraceCtx
called by 1: main
78func nx_span_enter(ctx: *NxTraceCtx, tag: *u8) -> i64
called by 1: main calls 2: nx_log_emitnx_log_puti
108func nx_span_exit(ctx: *NxTraceCtx, tag: *u8, id: i64) -> i64
called by 1: main calls 2: nx_log_emitnx_log_puti
131func main() -> i64