Skip to content

Commit

Permalink
add additional filter modes for allocation and alloc count over time
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed May 15, 2024
1 parent 27223f1 commit b8ba8c3
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions crates/turbopack-trace-server/src/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ pub enum ValueMode {
PersistentAllocations,
AllocationCount,
Count,
AllocationsPerTime,
PersistentAllocationsPerTime,
AllocationCountPerTime,
}

impl ValueMode {
Expand All @@ -45,6 +48,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 @@ -57,6 +63,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 @@ -69,6 +85,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 @@ -81,6 +107,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 @@ -93,6 +129,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 @@ -105,10 +153,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 @@ -321,6 +392,8 @@ impl Viewer {
"deallocations" => ValueMode::Deallocations,
"persistent-deallocations" => ValueMode::PersistentAllocations,
"allocation-count" => ValueMode::AllocationCount,
"allocations-per-time" => ValueMode::AllocationsPerTime,
"allocation-count-per-time" => ValueMode::AllocationCountPerTime,
"count" => ValueMode::Count,
_ => ValueMode::Duration,
};
Expand Down

0 comments on commit b8ba8c3

Please sign in to comment.