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
StreamStateInternal 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.
Buffer operations
ChromeTracing._make_stream_state — Function
_make_stream_state(capacity::Int) -> StreamStateAllocate a fresh StreamState with a ring buffer of capacity slots and no background writer attached.
ChromeTracing._ensure_stream_state — Function
_ensure_stream_state() -> StreamStateReturn the process-global StreamState, lazily creating one with DEFAULT_BUFFER_LIMIT slots if it does not exist yet.
ChromeTracing._append_event! — Function
_append_event!(stream::StreamState, event) -> BoolAppend 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.
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.
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.
ChromeTracing._flush_stream_state — Function
_flush_stream_state(stream::StreamState; finalize::Bool=false) -> IntDrain 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.
Helpers
ChromeTracing._now_ts — Function
_now_ts() -> IntCurrent monotonic timestamp in microseconds, the unit for the ts field.
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.
ChromeTracing._coerce_trace_key — Function
_coerce_trace_key(key) -> StringConvert a trace event key (a Symbol, AbstractString, or anything else) into a String suitable for use as a JSON object key.
ChromeTracing._write_json_array — Function
_write_json_array(path, events) -> IntWrite events to path as a single JSON array, creating the containing directory if needed. Returns the number of events written.