Internals

These are implementation details of the event buffer. They are not part of the public API and may change without a breaking release.

Buffer state

ChromeTracing.StreamState — Type
StreamState

Internal state for the single global trace buffer and its (optional) background writer task.

Events live in a fixed-size ring buffer (slots) that is written to without locks: a producer claims a slot by atomically bumping write_idx, stores its event, then publishes the slot by writing the claimed sequence number into slot_seq. The drain side only consumes a slot once its slot_seq matches the sequence it expects, so a slot that has been claimed but not yet filled is never read.

source

Buffer operations

ChromeTracing._append_event! — Function
_append_event!(stream::StreamState, event) -> Bool

Append event to stream's ring buffer without locking.

Returns true if the event was stored, or false if the buffer was full, in which case the event is dropped and stream.dropped is incremented. Dropping rather than blocking keeps tracing overhead bounded on the hot path.

source
ChromeTracing._drain_buffer! — Function
_drain_buffer!(stream::StreamState) -> Vector{Dict{String,Any}}

Remove and return every fully-published event from stream's ring buffer, in the order the events were recorded.

Only one thread drains at a time; if another drain is already in progress this returns an empty vector immediately. Draining also stops at the first slot that has been claimed by a producer but not yet published, so events are never returned out of order or half-written.

source
ChromeTracing._reset_buffer! — Function
_reset_buffer!(stream::StreamState)

Discard every buffered event in stream and reset its ring buffer indices and dropped-event counter back to their initial values.

source
ChromeTracing._flush_stream_state — Function
_flush_stream_state(stream::StreamState; finalize::Bool=false) -> Int

Drain stream's buffer and append the events to its open trace file, returning the number of events written. Returns 0 if stream is not currently writing to a file.

When finalize is true, the closing ] is written and the file is closed, so the trace on disk is a complete JSON array.

source

Helpers

ChromeTracing._normalize_args — Function
_normalize_args(args)

Convert args into a Dict with String keys, so that it round-trips through JSON as an object. Dicts, NamedTuples, generators and tuples of pairs are all accepted; anything else is returned unchanged.

source
ChromeTracing._coerce_trace_key — Function
_coerce_trace_key(key) -> String

Convert a trace event key (a Symbol, AbstractString, or anything else) into a String suitable for use as a JSON object key.

source
ChromeTracing._write_json_array — Function
_write_json_array(path, events) -> Int

Write events to path as a single JSON array, creating the containing directory if needed. Returns the number of events written.

source