From cc8a7d15806fde5dd0cf345405e1e1f3128c7c37 Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Fri, 8 Mar 2024 07:30:28 +0000 Subject: [PATCH] add additional filter modes for allocation and alloc count over time --- crates/turbopack-trace-server/src/viewer.rs | 94 +++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/crates/turbopack-trace-server/src/viewer.rs b/crates/turbopack-trace-server/src/viewer.rs index 513b53f9c0c72..8e3790fbdb7a5 100644 --- a/crates/turbopack-trace-server/src/viewer.rs +++ b/crates/turbopack-trace-server/src/viewer.rs @@ -32,6 +32,8 @@ pub enum ValueMode { PersistentAllocations, AllocationCount, Count, + AllocationsPerTime, + AllocationCountPerTime, } impl ValueMode { @@ -43,6 +45,24 @@ impl ValueMode { ValueMode::PersistentAllocations => span.total_persistent_allocations(), 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 + } + } + ValueMode::AllocationCountPerTime => { + let time = span.corrected_total_time(); + let allocations = span.total_allocation_count(); + if time == 0 { + 0 + } else { + allocations / time + } + } } } @@ -54,6 +74,24 @@ impl ValueMode { ValueMode::PersistentAllocations => graph.total_persistent_allocations(), 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 + } + } + ValueMode::AllocationCountPerTime => { + let time = graph.corrected_total_time(); + let allocations = graph.total_allocation_count(); + if time == 0 { + 0 + } else { + allocations / time + } + } } } @@ -65,6 +103,24 @@ impl ValueMode { ValueMode::PersistentAllocations => event.total_persistent_allocations(), 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 + } + } + ValueMode::AllocationCountPerTime => { + let time = event.corrected_total_time(); + let allocations = event.total_allocation_count(); + if time == 0 { + 0 + } else { + allocations / time + } + } } } @@ -76,6 +132,24 @@ 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 + } + } } } @@ -87,6 +161,24 @@ 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 + } + } } } } @@ -300,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, };