pub fn to_trace(dumps: &[Loaded], output: &Path) -> Result<usize>Expand description
Writes the loaded dumps to output as Chrome Trace Event Format JSON. Returns the event count.
The output is streamed: events are written one at a time straight to a buffered file, never
collected into an in-memory array. A trace can have hundreds of millions of events, and a
serde_json::Value per event (a heap map of boxed values) is far larger than its serialized
form — materializing them all is what made large dumps blow up memory. We instead make one cheap
pass to find orphaned spans (which needs only each record’s (span_id, phase), not its decoded
fields), then a second pass that decodes and emits each event’s JSON and immediately drops it.
Peak extra memory is therefore one event, not all of them.