Unverified Commit 7b01c98a authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

[turbopack-trace-server] Performance improvements for span event handling (#93179)

## What?

Performance improvements for the turbopack-trace-server, optimizing how
span events are stored, sorted, and retrieved.

## Why?

When processing large traces, the trace server was spending significant
time on:
1. Repeated sorting of events for each render in ExecutionOrder mode
2. Recomputing corrected self time on repeated lookups
3. Memory pressure from very large traces

## How?

### Lazy Sorting with LazySortedVec

Introduces a new `LazySortedVec<T>` data structure that stores events
unsorted and defers sorting until first read via `Deref`. Uses
`UnsafeCell` + `Once` for thread-safe one-time sorting. This avoids
repeated sorting overhead during trace ingestion.

### Pre-sorted Span Events by Start Time

- `SpanEvent::Child` now stores its `start: Timestamp` alongside the
index
- `SpanEvent` implements `Ord` to sort by start time (with SelfTime
before Child for equal timestamps)
- The viewer's `ExecutionOrder` mode no longer needs to sort - events
are already in order

### Cached Corrected Self Time

- `SpanEvent::SelfTime` now wraps a `SpanEventSelfTime` struct
containing an `OnceLock<Timestamp>` for `corrected_self_time`
- The expensive tree lookup is performed once and cached for subsequent
accesses
- `SpanEventSelfTimeRef` provides access to the cached value via
`corrected_self_time()`

### DROP_SPANS Environment Variable

Adds `DROP_SPANS=<count>` env var to skip the first N spans when loading
traces:
- Useful for reducing memory usage with very large traces
- Tracks dropped span IDs to also skip their subsequent events (End,
SelfTime, etc.)
- Stats output shows dropped span progress (e.g., "1000 spans, 500/1000
dropped")

<!-- NEXT_JS_LLM_PR -->

---------
Co-authored-by: 's avatarClaude Opus 4.7 (1M context) <noreply@anthropic.com>
parent e69de2ff
use std::{cell::UnsafeCell, ops::Deref, sync::Once};
pub struct LazySortedVec<T> {
vec: UnsafeCell<Vec<T>>,
once: Once,
}
unsafe impl<T> Send for LazySortedVec<T> where T: Send {}
unsafe impl<T> Sync for LazySortedVec<T> where T: Sync {}
impl<T> LazySortedVec<T> {
pub fn new() -> Self {
Self {
vec: UnsafeCell::new(Vec::new()),
once: Once::new(),
}
}
pub fn push(&mut self, value: T) {
self.once = Once::new();
self.vec.get_mut().push(value);
}
pub fn retain_unordered(&mut self, f: impl FnMut(&T) -> bool) {
self.vec.get_mut().retain(f);
}
pub fn iter_mut_unordered(&mut self) -> std::slice::IterMut<'_, T> {
self.vec.get_mut().iter_mut()
}
}
impl<T: Ord> Deref for LazySortedVec<T> {
type Target = Vec<T>;
fn deref(&self) -> &Self::Target {
let ptr = self.vec.get();
self.once.call_once(|| {
// SAFETY: The only access to the `vec` is through this `Deref` implementation, or we
// have a `&mut self` which prevents a simultaneous `Deref`. So we can guarantee that
// there are no other accesses to the `vec` while we sort it.
unsafe { &mut *ptr }.sort()
});
// SAFETY: Returning this reference is safe because the lifetime guarantees that there is no
// `&mut self` that could cause a simultaneous access to the `vec`, and the `Once`
// guarantees that the sorting is complete before we return the reference.
unsafe { &*ptr }
}
}
impl<T> Default for LazySortedVec<T> {
fn default() -> Self {
Self::new()
}
}
impl<T> From<Vec<T>> for LazySortedVec<T> {
fn from(vec: Vec<T>) -> Self {
Self {
vec: UnsafeCell::new(vec),
once: Once::new(),
}
}
}
...@@ -17,6 +17,7 @@ use self::{ ...@@ -17,6 +17,7 @@ use self::{
}; };
mod bottom_up; mod bottom_up;
mod lazy_sorted_vec;
mod reader; mod reader;
mod self_time_tree; mod self_time_tree;
mod server; mod server;
......
...@@ -12,6 +12,7 @@ use rustc_hash::FxHasher; ...@@ -12,6 +12,7 @@ use rustc_hash::FxHasher;
use self::{reader::TraceReader, server::serve, store_container::StoreContainer}; use self::{reader::TraceReader, server::serve, store_container::StoreContainer};
mod bottom_up; mod bottom_up;
mod lazy_sorted_vec;
mod reader; mod reader;
mod self_time_tree; mod self_time_tree;
mod server; mod server;
......
...@@ -128,6 +128,8 @@ impl InternalRowType<'_> { ...@@ -128,6 +128,8 @@ impl InternalRowType<'_> {
pub struct TurbopackFormat { pub struct TurbopackFormat {
store: Arc<StoreContainer>, store: Arc<StoreContainer>,
id_mapping: FxHashMap<u64, SpanIndex>, id_mapping: FxHashMap<u64, SpanIndex>,
dropped_ids: FxHashSet<u64>,
remaining_ids_to_drop: usize,
queued_rows: FxHashMap<u64, Vec<InternalRow<'static>>>, queued_rows: FxHashMap<u64, Vec<InternalRow<'static>>>,
outdated_spans: FxHashSet<SpanIndex>, outdated_spans: FxHashSet<SpanIndex>,
thread_stacks: FxHashMap<u64, Vec<u64>>, thread_stacks: FxHashMap<u64, Vec<u64>>,
...@@ -141,9 +143,15 @@ pub struct TurbopackFormat { ...@@ -141,9 +143,15 @@ pub struct TurbopackFormat {
impl TurbopackFormat { impl TurbopackFormat {
pub fn new(store: Arc<StoreContainer>) -> Self { pub fn new(store: Arc<StoreContainer>) -> Self {
let drop_ids = std::env::var("DROP_SPANS")
.ok()
.and_then(|v| v.parse::<usize>().ok())
.unwrap_or_default();
Self { Self {
store, store,
id_mapping: FxHashMap::with_capacity_and_hasher(131_072, Default::default()), id_mapping: FxHashMap::with_capacity_and_hasher(131_072, Default::default()),
dropped_ids: FxHashSet::with_capacity_and_hasher(drop_ids, Default::default()),
remaining_ids_to_drop: drop_ids,
queued_rows: FxHashMap::with_capacity_and_hasher(1_024, Default::default()), queued_rows: FxHashMap::with_capacity_and_hasher(1_024, Default::default()),
outdated_spans: FxHashSet::with_capacity_and_hasher(8_192, Default::default()), outdated_spans: FxHashSet::with_capacity_and_hasher(8_192, Default::default()),
thread_stacks: FxHashMap::with_capacity_and_hasher(64, Default::default()), thread_stacks: FxHashMap::with_capacity_and_hasher(64, Default::default()),
...@@ -377,6 +385,16 @@ impl TurbopackFormat { ...@@ -377,6 +385,16 @@ impl TurbopackFormat {
queue: &mut Vec<InternalRow<'static>>, queue: &mut Vec<InternalRow<'static>>,
) { ) {
let id = if let Some(id) = row.id { let id = if let Some(id) = row.id {
if matches!(
row.ty,
InternalRowType::End { .. }
| InternalRowType::Event { .. }
| InternalRowType::Record { .. }
| InternalRowType::SelfTime { .. }
) && self.dropped_ids.contains(&id)
{
return;
}
if let Some(id) = self.id_mapping.get(&id) { if let Some(id) = self.id_mapping.get(&id) {
Some(*id) Some(*id)
} else { } else {
...@@ -397,18 +415,28 @@ impl TurbopackFormat { ...@@ -397,18 +415,28 @@ impl TurbopackFormat {
target, target,
values, values,
} => { } => {
let span_id = store.add_span( if self.remaining_ids_to_drop > 0
id, && let Some(id) = id
ts, {
self.interner.intern_cow(target), self.remaining_ids_to_drop -= 1;
self.interner.intern_cow(name), self.dropped_ids.insert(new_id);
values self.id_mapping.insert(new_id, id);
.iter() } else {
.map(|(k, v)| (self.interner.intern(k), self.interner.intern_display(v))) let span_id = store.add_span(
.collect(), id,
&mut self.outdated_spans, ts,
); self.interner.intern_cow(target),
self.id_mapping.insert(new_id, span_id); self.interner.intern_cow(name),
values
.iter()
.map(|(k, v)| {
(self.interner.intern(k), self.interner.intern_display(v))
})
.collect(),
&mut self.outdated_spans,
);
self.id_mapping.insert(new_id, span_id);
}
if let Some(rows) = self.queued_rows.remove(&new_id) { if let Some(rows) = self.queued_rows.remove(&new_id) {
queue.extend(rows); queue.extend(rows);
} }
...@@ -496,7 +524,23 @@ impl TraceFormat for TurbopackFormat { ...@@ -496,7 +524,23 @@ impl TraceFormat for TurbopackFormat {
} }
fn stats(&self) -> String { fn stats(&self) -> String {
format!("{} spans", self.id_mapping.len()) use std::fmt::Write;
let spans = self.id_mapping.len();
let mut stats = format!("{spans} spans");
let dropped_spans = self.dropped_ids.len();
if dropped_spans > 0 {
let total_drop = dropped_spans + self.remaining_ids_to_drop;
write!(stats, ", {dropped_spans}/{total_drop} dropped").unwrap();
}
let queued_spans = self.queued_rows.len();
if queued_spans > 0 {
write!(stats, ", {queued_spans} queued").unwrap();
}
stats
} }
fn read(&mut self, mut buffer: &[u8], reuse: &mut Self::Reused) -> Result<usize> { fn read(&mut self, mut buffer: &[u8], reuse: &mut Self::Reused) -> Result<usize> {
......
...@@ -6,7 +6,7 @@ use std::{ ...@@ -6,7 +6,7 @@ use std::{
use hashbrown::HashMap; use hashbrown::HashMap;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use crate::timestamp::Timestamp; use crate::{lazy_sorted_vec::LazySortedVec, timestamp::Timestamp};
pub type SpanIndex = NonZeroUsize; pub type SpanIndex = NonZeroUsize;
...@@ -20,7 +20,8 @@ pub struct Span { ...@@ -20,7 +20,8 @@ pub struct Span {
pub args: Vec<(RcStr, RcStr)>, pub args: Vec<(RcStr, RcStr)>,
// This might change during writing: // This might change during writing:
pub events: Vec<SpanEvent>, /// The list of events sorted by start time
pub events: LazySortedVec<SpanEvent>,
pub is_complete: bool, pub is_complete: bool,
// These values are computed automatically: // These values are computed automatically:
...@@ -100,10 +101,62 @@ impl Span { ...@@ -100,10 +101,62 @@ impl Span {
} }
} }
#[derive(Copy, Clone, PartialEq, Eq)] pub struct SpanEventSelfTime {
pub start: Timestamp,
pub end: Timestamp,
pub corrected_self_time: OnceLock<Timestamp>,
}
pub enum SpanEvent { pub enum SpanEvent {
SelfTime { start: Timestamp, end: Timestamp }, SelfTime(SpanEventSelfTime),
Child { index: SpanIndex }, Child { start: Timestamp, index: SpanIndex },
}
impl SpanEvent {
pub fn self_time(start: Timestamp, end: Timestamp) -> Self {
Self::SelfTime(SpanEventSelfTime {
start,
end,
corrected_self_time: OnceLock::new(),
})
}
pub fn start(&self) -> Timestamp {
match self {
SpanEvent::SelfTime(self_time) => self_time.start,
SpanEvent::Child { start, .. } => *start,
}
}
}
impl PartialEq for SpanEvent {
fn eq(&self, other: &Self) -> bool {
self.cmp(other) == std::cmp::Ordering::Equal
}
}
impl Eq for SpanEvent {}
impl PartialOrd for SpanEvent {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for SpanEvent {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.start()
.cmp(&other.start())
.then_with(|| match (self, other) {
(SpanEvent::SelfTime(_), SpanEvent::Child { .. }) => std::cmp::Ordering::Less,
(SpanEvent::Child { .. }, SpanEvent::SelfTime(_)) => std::cmp::Ordering::Greater,
(SpanEvent::SelfTime(a), SpanEvent::SelfTime(b)) => a.end.cmp(&b.end),
(
SpanEvent::Child { start: _, index: a },
SpanEvent::Child { start: _, index: b },
) => a.cmp(b),
})
}
} }
#[derive(Clone)] #[derive(Clone)]
......
...@@ -13,7 +13,10 @@ use turbo_rcstr::{RcStr, rcstr}; ...@@ -13,7 +13,10 @@ use turbo_rcstr::{RcStr, rcstr};
use crate::{ use crate::{
FxIndexMap, FxIndexMap,
bottom_up::build_bottom_up_graph, bottom_up::build_bottom_up_graph,
span::{Span, SpanEvent, SpanExtra, SpanGraphEvent, SpanIndex, SpanNames, SpanTimeData}, span::{
Span, SpanEvent, SpanEventSelfTime, SpanExtra, SpanGraphEvent, SpanIndex, SpanNames,
SpanTimeData,
},
span_bottom_up_ref::SpanBottomUpRef, span_bottom_up_ref::SpanBottomUpRef,
span_graph_ref::{SpanGraphEventRef, SpanGraphRef, event_map_to_list}, span_graph_ref::{SpanGraphEventRef, SpanGraphRef, event_map_to_list},
store::{SpanId, Store}, store::{SpanId, Store},
...@@ -177,29 +180,33 @@ impl<'a> SpanRef<'a> { ...@@ -177,29 +180,33 @@ impl<'a> SpanRef<'a> {
1 1
} }
// TODO(sokra) use events instead of children for visualizing span graphs /// Events sorted by start time, including self time and children.
#[allow(dead_code)]
pub fn events(&self) -> impl DoubleEndedIterator<Item = SpanEventRef<'a>> { pub fn events(&self) -> impl DoubleEndedIterator<Item = SpanEventRef<'a>> {
self.span.events.iter().map(|event| match event { self.span
&SpanEvent::SelfTime { start, end } => SpanEventRef::SelfTime { .events
store: self.store, .iter()
start, .map(|event: &'a SpanEvent| match event {
end, SpanEvent::SelfTime(self_time) => SpanEventRef::SelfTime {
}, self_time: SpanEventSelfTimeRef {
SpanEvent::Child { index } => SpanEventRef::Child { store: self.store,
span: SpanRef { self_time,
span: &self.store.spans[index.get()], },
store: self.store,
index: index.get(),
}, },
}, SpanEvent::Child { index, .. } => SpanEventRef::Child {
}) span: SpanRef {
span: &self.store.spans[index.get()],
store: self.store,
index: index.get(),
},
},
})
} }
/// Children sorted by start time, excluding self time.
pub fn children(&self) -> impl DoubleEndedIterator<Item = SpanRef<'a>> + 'a + use<'a> { pub fn children(&self) -> impl DoubleEndedIterator<Item = SpanRef<'a>> + 'a + use<'a> {
self.span.events.iter().filter_map(|event| match event { self.span.events.iter().filter_map(|event| match event {
SpanEvent::SelfTime { .. } => None, SpanEvent::SelfTime { .. } => None,
SpanEvent::Child { index } => Some(SpanRef { SpanEvent::Child { index, .. } => Some(SpanRef {
span: &self.store.spans[index.get()], span: &self.store.spans[index.get()],
store: self.store, store: self.store,
index: index.get(), index: index.get(),
...@@ -207,10 +214,11 @@ impl<'a> SpanRef<'a> { ...@@ -207,10 +214,11 @@ impl<'a> SpanRef<'a> {
}) })
} }
/// Children sorted by start time, excluding self time, in parallel.
pub fn children_par(&self) -> impl ParallelIterator<Item = SpanRef<'a>> + 'a { pub fn children_par(&self) -> impl ParallelIterator<Item = SpanRef<'a>> + 'a {
self.span.events.par_iter().filter_map(|event| match event { self.span.events.par_iter().filter_map(|event| match event {
SpanEvent::SelfTime { .. } => None, SpanEvent::SelfTime { .. } => None,
SpanEvent::Child { index } => Some(SpanRef { SpanEvent::Child { index, .. } => Some(SpanRef {
span: &self.store.spans[index.get()], span: &self.store.spans[index.get()],
store: self.store, store: self.store,
index: index.get(), index: index.get(),
...@@ -285,17 +293,11 @@ impl<'a> SpanRef<'a> { ...@@ -285,17 +293,11 @@ impl<'a> SpanRef<'a> {
.span .span
.events .events
.par_iter() .par_iter()
.filter_map(|event| { .filter_map(|event: &'a SpanEvent| {
if let SpanEvent::SelfTime { start, end } = event { if let SpanEvent::SelfTime(self_time) = event {
let duration = *end - *start; return Some(
if !duration.is_zero() { SpanEventSelfTimeRef { store, self_time }.corrected_self_time(),
store.set_max_self_time_lookup(*end); );
let corrected_time =
store.self_time_tree.as_ref().map_or(duration, |tree| {
tree.lookup_range_corrected_time(*start, *end)
});
return Some(corrected_time);
}
} }
None None
}) })
...@@ -558,47 +560,53 @@ impl Debug for SpanRef<'_> { ...@@ -558,47 +560,53 @@ impl Debug for SpanRef<'_> {
} }
} }
#[allow(dead_code)] pub struct SpanEventSelfTimeRef<'a> {
#[derive(Copy, Clone)] store: &'a Store,
pub enum SpanEventRef<'a> { self_time: &'a SpanEventSelfTime,
SelfTime {
store: &'a Store,
start: Timestamp,
end: Timestamp,
},
Child {
span: SpanRef<'a>,
},
} }
impl SpanEventRef<'_> { impl<'a> SpanEventSelfTimeRef<'a> {
pub fn start(&self) -> Timestamp { pub fn start(&self) -> Timestamp {
match self { self.self_time.start
SpanEventRef::SelfTime { start, .. } => *start,
SpanEventRef::Child { span } => span.start(),
}
} }
pub fn end(&self) -> Timestamp {
self.self_time.end
}
pub fn corrected_self_time(&self) -> Timestamp {
*self.self_time.corrected_self_time.get_or_init(|| {
let duration = self.self_time.end - self.self_time.start;
if !duration.is_zero() {
self.store.set_max_self_time_lookup(self.self_time.end);
self.store.self_time_tree.as_ref().map_or(duration, |tree| {
tree.lookup_range_corrected_time(self.self_time.start, self.self_time.end)
})
} else {
Timestamp::ZERO
}
})
}
}
pub enum SpanEventRef<'a> {
SelfTime { self_time: SpanEventSelfTimeRef<'a> },
Child { span: SpanRef<'a> },
}
impl SpanEventRef<'_> {
pub fn total_time(&self) -> Timestamp { pub fn total_time(&self) -> Timestamp {
match self { match self {
SpanEventRef::SelfTime { start, end, .. } => end.saturating_sub(*start), SpanEventRef::SelfTime {
self_time: event, ..
} => event.end().saturating_sub(event.start()),
SpanEventRef::Child { span } => span.total_time(), SpanEventRef::Child { span } => span.total_time(),
} }
} }
pub fn corrected_self_time(&self) -> Timestamp { pub fn corrected_self_time(&self) -> Timestamp {
match self { match self {
SpanEventRef::SelfTime { store, start, end } => { SpanEventRef::SelfTime { self_time: event } => event.corrected_self_time(),
let duration = *end - *start;
if !duration.is_zero() {
store.set_max_self_time_lookup(*end);
store.self_time_tree.as_ref().map_or(duration, |tree| {
tree.lookup_range_corrected_time(*start, *end)
})
} else {
Timestamp::ZERO
}
}
SpanEventRef::Child { span } => span.corrected_self_time(), SpanEventRef::Child { span } => span.corrected_self_time(),
} }
} }
......
...@@ -46,7 +46,7 @@ fn new_root_span() -> Span { ...@@ -46,7 +46,7 @@ fn new_root_span() -> Span {
category: RcStr::default(), category: RcStr::default(),
name: rcstr!("(root)"), name: rcstr!("(root)"),
args: vec![], args: vec![],
events: vec![], events: Default::default(),
is_complete: true, is_complete: true,
max_depth: OnceLock::new(), max_depth: OnceLock::new(),
self_allocations: 0, self_allocations: 0,
...@@ -120,7 +120,7 @@ impl Store { ...@@ -120,7 +120,7 @@ impl Store {
category, category,
name, name,
args, args,
events: vec![], events: vec![].into(),
is_complete: false, is_complete: false,
max_depth: OnceLock::new(), max_depth: OnceLock::new(),
self_allocations: 0, self_allocations: 0,
...@@ -152,7 +152,7 @@ impl Store { ...@@ -152,7 +152,7 @@ impl Store {
depth = CUT_OFF_DEPTH - 1; depth = CUT_OFF_DEPTH - 1;
} }
if depth < CUT_OFF_DEPTH { if depth < CUT_OFF_DEPTH {
parent.events.push(SpanEvent::Child { index: id }); parent.events.push(SpanEvent::Child { start, index: id });
} }
parent.start = min(parent.start, start); parent.start = min(parent.start, start);
let span = &mut self.spans[id.get()]; let span = &mut self.spans[id.get()];
...@@ -221,7 +221,7 @@ impl Store { ...@@ -221,7 +221,7 @@ impl Store {
outdated_spans.insert(span_index); outdated_spans.insert(span_index);
time_data.self_time += end - start; time_data.self_time += end - start;
time_data.self_end = max(time_data.self_end, end); time_data.self_end = max(time_data.self_end, end);
span.events.push(SpanEvent::SelfTime { start, end }); span.events.push(SpanEvent::self_time(start, end));
self.insert_self_time(start, end, span_index, outdated_spans); self.insert_self_time(start, end, span_index, outdated_spans);
} }
...@@ -249,31 +249,25 @@ impl Store { ...@@ -249,31 +249,25 @@ impl Store {
for (start, end, index) in children { for (start, end, index) in children {
if start > current { if start > current {
if start > self_end { if start > self_end {
events.push(SpanEvent::SelfTime { events.push(SpanEvent::self_time(current, self_end));
start: current,
end: self_end,
});
self.insert_self_time(current, self_end, span_index, outdated_spans); self.insert_self_time(current, self_end, span_index, outdated_spans);
self_time += self_end - current; self_time += self_end - current;
break; break;
} }
events.push(SpanEvent::SelfTime { events.push(SpanEvent::self_time(current, start));
start: current,
end: start,
});
self.insert_self_time(current, start, span_index, outdated_spans); self.insert_self_time(current, start, span_index, outdated_spans);
self_time += start - current; self_time += start - current;
} }
events.push(SpanEvent::Child { index }); events.push(SpanEvent::Child { start, index });
current = max(current, end); current = max(current, end);
} }
current -= start_time; current -= start_time;
if current < total_time { if current < total_time {
self_time += total_time - current; self_time += total_time - current;
events.push(SpanEvent::SelfTime { events.push(SpanEvent::self_time(
start: current + start_time, current + start_time,
end: start_time + total_time, start_time + total_time,
}); ));
self.insert_self_time( self.insert_self_time(
current + start_time, current + start_time,
start_time + total_time, start_time + total_time,
...@@ -286,7 +280,7 @@ impl Store { ...@@ -286,7 +280,7 @@ impl Store {
let time_data = span.time_data_mut(); let time_data = span.time_data_mut();
time_data.self_time = self_time; time_data.self_time = self_time;
time_data.self_end = self_end; time_data.self_end = self_end;
span.events = events; span.events = events.into();
span.start = start_time; span.start = start_time;
} }
...@@ -298,6 +292,7 @@ impl Store { ...@@ -298,6 +292,7 @@ impl Store {
) { ) {
outdated_spans.insert(span_index); outdated_spans.insert(span_index);
let span = &mut self.spans[span_index.get()]; let span = &mut self.spans[span_index.get()];
let span_start = span.start;
let old_parent = span.parent.replace(parent); let old_parent = span.parent.replace(parent);
let old_parent = if let Some(parent) = old_parent { let old_parent = if let Some(parent) = old_parent {
...@@ -306,17 +301,16 @@ impl Store { ...@@ -306,17 +301,16 @@ impl Store {
} else { } else {
&mut self.spans[0] &mut self.spans[0]
}; };
if let Some(index) = old_parent old_parent.events.retain_unordered(
.events |event: &SpanEvent| !matches!(event, SpanEvent::Child { index, .. } if *index == span_index),
.iter() );
.position(|event| *event == SpanEvent::Child { index: span_index })
{
old_parent.events.remove(index);
}
outdated_spans.insert(parent); outdated_spans.insert(parent);
let parent = &mut self.spans[parent.get()]; let parent = &mut self.spans[parent.get()];
parent.events.push(SpanEvent::Child { index: span_index }); parent.events.push(SpanEvent::Child {
start: span_start,
index: span_index,
});
} }
pub fn add_allocation( pub fn add_allocation(
...@@ -397,6 +391,11 @@ impl Store { ...@@ -397,6 +391,11 @@ impl Store {
time_data.corrected_self_time.take(); time_data.corrected_self_time.take();
time_data.corrected_total_time.take(); time_data.corrected_total_time.take();
} }
for event in span.events.iter_mut_unordered() {
if let SpanEvent::SelfTime(self_time) = event {
self_time.corrected_self_time.take();
}
}
span.total_allocations.take(); span.total_allocations.take();
span.total_deallocations.take(); span.total_deallocations.take();
span.total_persistent_allocations.take(); span.total_persistent_allocations.take();
...@@ -424,7 +423,7 @@ impl Store { ...@@ -424,7 +423,7 @@ impl Store {
pub fn root_spans(&self) -> impl Iterator<Item = SpanRef<'_>> { pub fn root_spans(&self) -> impl Iterator<Item = SpanRef<'_>> {
self.spans[0].events.iter().filter_map(|event| match event { self.spans[0].events.iter().filter_map(|event| match event {
&SpanEvent::Child { index: id } => Some(SpanRef { &SpanEvent::Child { index: id, .. } => Some(SpanRef {
span: &self.spans[id.get()], span: &self.spans[id.get()],
store: self, store: self,
index: id.get(), index: id.get(),
......
...@@ -706,9 +706,7 @@ impl Viewer { ...@@ -706,9 +706,7 @@ impl Viewer {
(title.to_string(), cat.to_string()) (title.to_string(), cat.to_string())
})) }))
} }
SortMode::ExecutionOrder => { SortMode::ExecutionOrder => Either::Right(span.events()),
Either::Right(span.events().sorted_by_key(|child| child.start()))
}
}; };
for child in spans { for child in spans {
match child { match child {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment