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 906b939 commit 3b94a1f
Showing 1 changed file with 57 additions and 78 deletions.
135 changes: 57 additions & 78 deletions crates/turbopack-trace-server/src/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub enum ValueMode {
AllocationCount,
Count,
AllocationsPerTime,
PersistentAllocationsPerTime,
AllocationCountPerTime,
}

Expand All @@ -47,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 @@ -60,23 +64,15 @@ impl ValueMode {
ValueMode::AllocationCount => span.total_allocation_count(),
ValueMode::Count => span.total_span_count(),
ValueMode::AllocationsPerTime => {
let time = span.corrected_total_time();
let allocations = span.total_allocations();
if time == 0 {
0
} else {
allocations / time
}
value_over_time(span.total_allocations(), span.corrected_total_time())
}
ValueMode::AllocationCountPerTime => {
let time = span.corrected_total_time();
let allocations = span.total_allocation_count();
if time == 0 {
0
} else {
allocations / time
}
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 @@ -90,23 +86,15 @@ impl ValueMode {
ValueMode::AllocationCount => graph.total_allocation_count(),
ValueMode::Count => graph.total_span_count(),
ValueMode::AllocationsPerTime => {
let time = graph.corrected_total_time();
let allocations = graph.total_allocations();
if time == 0 {
0
} else {
allocations / time
}
value_over_time(graph.total_allocations(), graph.corrected_total_time())
}
ValueMode::AllocationCountPerTime => {
let time = graph.corrected_total_time();
let allocations = graph.total_allocation_count();
if time == 0 {
0
} else {
allocations / time
}
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 @@ -120,23 +108,15 @@ impl ValueMode {
ValueMode::AllocationCount => event.total_allocation_count(),
ValueMode::Count => event.total_span_count(),
ValueMode::AllocationsPerTime => {
let time = event.corrected_total_time();
let allocations = event.total_allocations();
if time == 0 {
0
} else {
allocations / time
}
value_over_time(event.total_allocations(), event.corrected_total_time())
}
ValueMode::AllocationCountPerTime => {
let time = event.corrected_total_time();
let allocations = event.total_allocation_count();
if time == 0 {
0
} else {
allocations / time
}
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 @@ -149,24 +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 => {
let time = bottom_up.corrected_self_time();
let allocations = bottom_up.self_allocations();
if time == 0 {
0
} else {
allocations / time
}
}
ValueMode::AllocationCountPerTime => {
let time = bottom_up.corrected_self_time();
let allocations = bottom_up.self_allocation_count();
if time == 0 {
0
} else {
allocations / time
}
}
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 @@ -179,28 +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 => {
let time = bottom_up_span.corrected_self_time();
let allocations = bottom_up_span.self_allocations();
if time == 0 {
0
} else {
allocations / time
}
}
ValueMode::AllocationCountPerTime => {
let time = bottom_up_span.corrected_self_time();
let allocations = bottom_up_span.self_allocation_count();
if time == 0 {
0
} else {
allocations / time
}
}
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

0 comments on commit 3b94a1f

Please sign in to comment.