Skip to main content

Live trace pipeline

Publish trace snapshots while the capture is still arriving.

The Chrome trace streaming helpers accept event, JSON, or Arrow chunk streams and adapt them into deterministic TraceStreamChunk snapshots. The consumer can render progress without taking ownership of the parser.

The live trace path

Accept chunks. Accumulate semantics. Publish a stable view.

The session keeps enough logical state to handle metadata, begin/end pairs, flows, and counters that can affect earlier rows, while publication frequency remains configurable.

Input

Events, JSON chunks, or Arrow batches

Accumulate

One semantic event state for the active stream

Publish

Replacement snapshots at a chosen threshold

Consume

Render updates or await the final snapshot

The Chrome streaming APIs adapt JSON chunks, Arrow batches, or already parsed events into the module's TraceStreamChunk contract. TraceStreamSession remains independent of Arrow and loader objects.

Detailed guide

Streaming and snapshot details

The reference below covers input paths, consumer helpers, options, metadata precedence, publication thresholds, and snapshot semantics.

Input Paths​

HelperInput
streamChromeTraceEventChunksAsync events or event arrays.
streamChromeTraceArrowChunksAsync Chrome Arrow tables or record batches.
streamChromeTraceFileChunksAsync string, ArrayBuffer, or typed-array JSON chunks.

The file path uses the same JSON-to-Arrow parser as ChromeTraceLoader, then adapts Arrow rows back to logical events. All three paths share the same event accumulator and semantic trace builder.

import {createTraceStreamSession} from '@loaders.gl/traces/stream';
import {streamChromeTraceFileChunks} from '@loaders.gl/traces/chrome-trace';

const session = createTraceStreamSession();

for await (const chunk of streamChromeTraceFileChunks(response.body, {
name: 'Live capture',
batchSize: 1024,
publishEveryEvents: 2048
})) {
session.applyChunk(chunk);
const snapshot = session.publishSnapshot();
render(snapshot);
}

Consumer Helpers​

The matching consumeChromeTraceEventStream, consumeChromeTraceArrowStream, and consumeChromeTraceFileStream helpers apply every generated chunk to a supplied session and return the latest published snapshot.

import {consumeChromeTraceArrowStream} from '@loaders.gl/traces/chrome-trace';
import {createTraceStreamSession} from '@loaders.gl/traces/stream';

const session = createTraceStreamSession({name: 'Imported trace'});
const unsubscribe = session.subscribe(snapshot => render(snapshot));

const finalSnapshot = await consumeChromeTraceArrowStream(session, arrowBatches, {
publishEveryEvents: 500
});

unsubscribe();
session.close();

Options​

OptionTypeDefaultDescription
namestring'Chrome Trace Live Stream'Snapshot name.
displayTimeUnitstringdiscovered metadataInitial or fallback display unit.
metadataRecord<string, unknown>discovered metadataInitial or fallback top-level metadata.
batchSizenumberparser defaultEvents per JSON-to-Arrow parser batch.
publishEveryEventsnumber256New events required before publishing a replacement chunk.
maxLengthnumber1000Maximum events structurally validated during semantic assembly.

Metadata discovered on Arrow schemas takes precedence over fallback displayTimeUnit and metadata options.

Snapshot Semantics​

Each emitted chunk is a full replacement snapshot assembled from every event received so far. This keeps live consumers deterministic when begin/end pairs, metadata, flows, or counters affect earlier semantic structures. The accumulator therefore retains logical events for the duration of the stream. publishEveryEvents controls rebuild frequency, not retained event count.

The final accumulated snapshot is emitted even when the last group contains fewer events than the publish threshold.