diff --git a/src/allocator/dedicated_block_allocator/mod.rs b/src/allocator/dedicated_block_allocator/mod.rs index 746b4dcd..da091d8e 100644 --- a/src/allocator/dedicated_block_allocator/mod.rs +++ b/src/allocator/dedicated_block_allocator/mod.rs @@ -16,7 +16,7 @@ pub(crate) struct DedicatedBlockAllocator { allocated: u64, /// Only used if [`crate::AllocatorDebugSettings::store_stack_traces`] is [`true`] name: Option, - backtrace: Arc, + backtrace: Option>, } impl DedicatedBlockAllocator { @@ -25,7 +25,7 @@ impl DedicatedBlockAllocator { size, allocated: 0, name: None, - backtrace: Arc::new(Backtrace::disabled()), + backtrace: None, } } } @@ -39,7 +39,7 @@ impl SubAllocator for DedicatedBlockAllocator { _allocation_type: AllocationType, _granularity: u64, name: &str, - backtrace: Arc, + backtrace: Option>, ) -> Result<(u64, std::num::NonZeroU64)> { if self.allocated != 0 { return Err(AllocationError::OutOfMemory); @@ -106,7 +106,7 @@ impl SubAllocator for DedicatedBlockAllocator { memory_block_index, self.size, name, - self.backtrace + self.backtrace.as_deref().unwrap_or(&Backtrace::disabled()) ) } diff --git a/src/allocator/free_list_allocator/mod.rs b/src/allocator/free_list_allocator/mod.rs index d7cde2e8..0a1b4d14 100644 --- a/src/allocator/free_list_allocator/mod.rs +++ b/src/allocator/free_list_allocator/mod.rs @@ -32,7 +32,7 @@ pub(crate) struct MemoryChunk { pub(crate) allocation_type: AllocationType, pub(crate) name: Option, /// Only used if [`crate::AllocatorDebugSettings::store_stack_traces`] is [`true`] - pub(crate) backtrace: Arc, + pub(crate) backtrace: Option>, next: Option, prev: Option, } @@ -79,7 +79,7 @@ impl FreeListAllocator { offset: 0, allocation_type: AllocationType::Free, name: None, - backtrace: Arc::new(Backtrace::disabled()), + backtrace: None, prev: None, next: None, }, @@ -162,7 +162,7 @@ impl SubAllocator for FreeListAllocator { allocation_type: AllocationType, granularity: u64, name: &str, - backtrace: Arc, + backtrace: Option>, ) -> Result<(u64, std::num::NonZeroU64)> { let free_size = self.size - self.allocated; if size > free_size { @@ -302,7 +302,7 @@ impl SubAllocator for FreeListAllocator { })?; chunk.allocation_type = AllocationType::Free; chunk.name = None; - chunk.backtrace = Arc::new(Backtrace::disabled()); + chunk.backtrace = None; self.allocated -= chunk.size; @@ -384,7 +384,7 @@ impl SubAllocator for FreeListAllocator { chunk.offset, chunk.allocation_type, name, - chunk.backtrace + chunk.backtrace.as_deref().unwrap_or(&Backtrace::disabled()) ); } } diff --git a/src/allocator/mod.rs b/src/allocator/mod.rs index 5d40bbf6..3a65b70e 100644 --- a/src/allocator/mod.rs +++ b/src/allocator/mod.rs @@ -39,7 +39,7 @@ pub struct AllocationReport { /// The size in bytes of the allocation. pub size: u64, #[cfg(feature = "visualizer")] - pub(crate) backtrace: Arc, + pub(crate) backtrace: Option>, } /// Describes a memory block in the [`AllocatorReport`]. @@ -113,7 +113,7 @@ pub(crate) trait SubAllocator: SubAllocatorBase + fmt::Debug + Sync + Send { allocation_type: AllocationType, granularity: u64, name: &str, - backtrace: Arc, + backtrace: Option>, ) -> Result<(u64, std::num::NonZeroU64)>; fn free(&mut self, chunk_id: Option) -> Result<()>; diff --git a/src/d3d12/mod.rs b/src/d3d12/mod.rs index cb9b29bf..264f9627 100644 --- a/src/d3d12/mod.rs +++ b/src/d3d12/mod.rs @@ -435,7 +435,7 @@ impl MemoryType { &mut self, device: &ID3D12DeviceVersion, desc: &AllocationCreateDesc<'_>, - backtrace: Arc, + backtrace: Option>, allocation_sizes: &AllocationSizes, ) -> Result { let allocation_type = AllocationType::Linear; @@ -728,11 +728,11 @@ impl Allocator { let size = desc.size; let alignment = desc.alignment; - let backtrace = Arc::new(if self.debug_settings.store_stack_traces { - Backtrace::force_capture() + let backtrace = if self.debug_settings.store_stack_traces { + Some(Arc::new(Backtrace::force_capture())) } else { - Backtrace::disabled() - }); + None + }; if self.debug_settings.log_allocations { debug!( diff --git a/src/metal/mod.rs b/src/metal/mod.rs index ad835711..5ec6a24d 100644 --- a/src/metal/mod.rs +++ b/src/metal/mod.rs @@ -243,7 +243,7 @@ impl MemoryType { &mut self, device: &ProtocolObject, desc: &AllocationCreateDesc<'_>, - backtrace: Arc, + backtrace: Option>, allocation_sizes: &AllocationSizes, ) -> Result { let allocation_type = allocator::AllocationType::Linear; @@ -470,11 +470,11 @@ impl Allocator { let size = desc.size; let alignment = desc.alignment; - let backtrace = Arc::new(if self.debug_settings.store_stack_traces { - Backtrace::force_capture() + let backtrace = if self.debug_settings.store_stack_traces { + Some(Arc::new(Backtrace::force_capture())) } else { - Backtrace::disabled() - }); + None + }; if self.debug_settings.log_allocations { debug!( diff --git a/src/visualizer/allocation_reports.rs b/src/visualizer/allocation_reports.rs index c95b51ae..b726f187 100644 --- a/src/visualizer/allocation_reports.rs +++ b/src/visualizer/allocation_reports.rs @@ -126,10 +126,12 @@ pub(crate) fn render_allocation_reports_ui( ui.label(name); }); - if backtrace.status() == BacktraceStatus::Captured { - resp.1.on_hover_ui(|ui| { - ui.label(backtrace.to_string()); - }); + if let Some(backtrace) = backtrace { + if backtrace.status() == BacktraceStatus::Captured { + resp.1.on_hover_ui(|ui| { + ui.label(backtrace.to_string()); + }); + } } row.col(|ui| { diff --git a/src/visualizer/memory_chunks.rs b/src/visualizer/memory_chunks.rs index ffe2afed..88fbb978 100644 --- a/src/visualizer/memory_chunks.rs +++ b/src/visualizer/memory_chunks.rs @@ -114,10 +114,12 @@ pub(crate) fn render_memory_chunks_ui<'a>( if let Some(name) = &chunk.name { ui.label(format!("name: {}", name)); } - if settings.show_backtraces - && chunk.backtrace.status() == BacktraceStatus::Captured - { - ui.label(chunk.backtrace.to_string()); + if settings.show_backtraces { + if let Some(backtrace) = chunk.backtrace.as_ref() { + if backtrace.status() == BacktraceStatus::Captured { + ui.label(backtrace.to_string()); + } + } } }); } diff --git a/src/vulkan/mod.rs b/src/vulkan/mod.rs index 1e6a4727..ee81271a 100644 --- a/src/vulkan/mod.rs +++ b/src/vulkan/mod.rs @@ -452,7 +452,7 @@ impl MemoryType { device: &ash::Device, desc: &AllocationCreateDesc<'_>, granularity: u64, - backtrace: Arc, + backtrace: Option>, allocation_sizes: &AllocationSizes, ) -> Result { let allocation_type = if desc.linear { @@ -765,11 +765,11 @@ impl Allocator { let size = desc.requirements.size; let alignment = desc.requirements.alignment; - let backtrace = Arc::new(if self.debug_settings.store_stack_traces { - Backtrace::force_capture() + let backtrace = if self.debug_settings.store_stack_traces { + Some(Arc::new(Backtrace::force_capture())) } else { - Backtrace::disabled() - }); + None + }; if self.debug_settings.log_allocations { debug!(