Skip to main content

Module linux_trace

Module linux_trace 

Source
Expand description

Process-wide Linux ftrace / portable perf-trace backend for Bun__linux_trace_{init,emit,close}.

§ABI (matches bun_core::perf::sys / upstream perf.zig)

int  Bun__linux_trace_init(void);                        // 1 = backend ready, 0 = not
void Bun__linux_trace_close(void);
int  Bun__linux_trace_emit(const char *event_name, int64_t duration_ns);
// emit: 0 = success, non-zero = failure

§Backends

OSBackend
Linux/Androidtrace_marker (/sys/kernel/tracing then debugfs)
macOSin-process ring + temp bao-perf-trace.jsonl
WindowsOutputDebugStringW + temp jsonl + ring

All platforms keep a process-local ring (4096 slots) so unit tests can observe emit side effects when init succeeded.

Structs§

TraceRingEvent
One captured emit for tests / consumers of the ring.

Functions§

Bun__linux_trace_close
Close the backend and release OS resources. Idempotent / re-entrant safe. Does not wipe the ring (tests may inspect after close); call linux_trace_reset_for_test to clear.
Bun__linux_trace_emit
Emit one complete event: event_name + duration_ns.
Bun__linux_trace_init
Initialize the platform trace backend.
force_link_linux_trace
Keep this compilation unit on the product link line.
linux_trace_emit_ok
Successful emit count since last reset (backend-write OK).
linux_trace_reset_for_test
Close backend + clear ring + counters (test isolation).
linux_trace_ring_len
Number of events currently held in the ring.
linux_trace_ring_snapshot
Snapshot of ring events in chronological order (oldest → newest).