Skip to content

Commit

Permalink
[turbo-trace] add additional filter modes for allocs over time (verce…
Browse files Browse the repository at this point in the history
…l/turborepo#7673)

This adds a few modes to see allocations per unit time. The viewer is
a bit borked but by selecting the one you want to inspect and changing the
view for sub-items you can usually find some useful data.
  • Loading branch information
arlyon authored May 22, 2024
1 parent f5fc980 commit e170a45
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions crates/turbopack-trace-server/src/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ pub enum ValueMode {
PersistentAllocations,
AllocationCount,
Count,
AllocationsPerTime,
PersistentAllocationsPerTime,
AllocationCountPerTime,
}

impl ValueMode {
Expand All @@ -46,6 +49,9 @@ impl ValueMode {
ValueMode::PersistentAllocations => ValueMode::Allocations,
ValueMode::AllocationCount => ValueMode::Allocations,
ValueMode::Count => ValueMode::Count,
ValueMode::AllocationsPerTime => ValueMode::PersistentAllocationsPerTime,
ValueMode::PersistentAllocationsPerTime => ValueMode::AllocationsPerTime,
ValueMode::AllocationCountPerTime => ValueMode::AllocationsPerTime,
}
}

Expand All @@ -58,6 +64,16 @@ impl ValueMode {
ValueMode::PersistentAllocations => span.total_persistent_allocations(),
ValueMode::AllocationCount => span.total_allocation_count(),
ValueMode::Count => span.total_span_count(),
ValueMode::AllocationsPerTime => {
value_over_time(span.total_allocations(), span.corrected_total_time())
}
ValueMode::AllocationCountPerTime => {
value_over_time(span.total_allocation_count(), span.corrected_total_time())
}
ValueMode::PersistentAllocationsPerTime => value_over_time(
span.total_persistent_allocations(),
span.corrected_total_time(),
),
}
}

Expand All @@ -70,6 +86,16 @@ impl ValueMode {
ValueMode::PersistentAllocations => graph.total_persistent_allocations(),
ValueMode::AllocationCount => graph.total_allocation_count(),
ValueMode::Count => graph.total_span_count(),
ValueMode::AllocationsPerTime => {
value_over_time(graph.total_allocations(), graph.corrected_total_time())
}
ValueMode::AllocationCountPerTime => {
value_over_time(graph.total_allocation_count(), graph.corrected_total_time())
}
ValueMode::PersistentAllocationsPerTime => value_over_time(
graph.total_persistent_allocations(),
graph.corrected_total_time(),
),
}
}

Expand All @@ -82,6 +108,16 @@ impl ValueMode {
ValueMode::PersistentAllocations => event.total_persistent_allocations(),
ValueMode::AllocationCount => event.total_allocation_count(),
ValueMode::Count => event.total_span_count(),
ValueMode::AllocationsPerTime => {
value_over_time(event.total_allocations(), event.corrected_total_time())
}
ValueMode::AllocationCountPerTime => {
value_over_time(event.total_allocation_count(), event.corrected_total_time())
}
ValueMode::PersistentAllocationsPerTime => value_over_time(
event.total_persistent_allocations(),
event.corrected_total_time(),
),
}
}

Expand All @@ -94,6 +130,18 @@ impl ValueMode {
ValueMode::PersistentAllocations => bottom_up.self_persistent_allocations(),
ValueMode::AllocationCount => bottom_up.self_allocation_count(),
ValueMode::Count => bottom_up.self_span_count(),
ValueMode::AllocationsPerTime => value_over_time(
bottom_up.self_allocations(),
bottom_up.corrected_self_time(),
),
ValueMode::AllocationCountPerTime => value_over_time(
bottom_up.self_allocation_count(),
bottom_up.corrected_self_time(),
),
ValueMode::PersistentAllocationsPerTime => value_over_time(
bottom_up.self_persistent_allocations(),
bottom_up.corrected_self_time(),
),
}
}

Expand All @@ -106,10 +154,33 @@ impl ValueMode {
ValueMode::PersistentAllocations => bottom_up_span.self_persistent_allocations(),
ValueMode::AllocationCount => bottom_up_span.self_allocation_count(),
ValueMode::Count => bottom_up_span.self_span_count(),
ValueMode::AllocationsPerTime => value_over_time(
bottom_up_span.self_allocations(),
bottom_up_span.corrected_self_time(),
),
ValueMode::AllocationCountPerTime => value_over_time(
bottom_up_span.self_allocation_count(),
bottom_up_span.corrected_self_time(),
),
ValueMode::PersistentAllocationsPerTime => value_over_time(
bottom_up_span.self_persistent_allocations(),
bottom_up_span.corrected_self_time(),
),
}
}
}

/// this is unfortunately int division but itll have to do.
///
/// cases where count per time is very low is probably not important
fn value_over_time(value: u64, time: u64) -> u64 {
if time == 0 {
0
} else {
value / time
}
}

#[derive(Clone, Copy, Debug)]
pub enum ViewMode {
RawSpans { sorted: bool },
Expand Down Expand Up @@ -335,6 +406,9 @@ impl Viewer {
"deallocations" => ValueMode::Deallocations,
"persistent-deallocations" => ValueMode::PersistentAllocations,
"allocation-count" => ValueMode::AllocationCount,
"allocations-per-time" => ValueMode::AllocationsPerTime,
"allocation-count-per-time" => ValueMode::AllocationCountPerTime,
"persistent-allocations-per-time" => ValueMode::PersistentAllocationsPerTime,
"count" => ValueMode::Count,
_ => ValueMode::Duration,
};
Expand Down

0 comments on commit e170a45

Please sign in to comment.