33#[ cfg( feature = "visualizer" ) ]
44pub ( crate ) mod visualizer;
55
6- use super :: { AllocationType , SubAllocator , SubAllocatorBase } ;
6+ use super :: { resolve_backtrace , AllocationReport , AllocationType , SubAllocator , SubAllocatorBase } ;
77use crate :: { AllocationError , Result } ;
88
99use log:: { log, Level } ;
@@ -26,7 +26,7 @@ pub(crate) struct MemoryChunk {
2626 pub ( crate ) offset : u64 ,
2727 pub ( crate ) allocation_type : AllocationType ,
2828 pub ( crate ) name : Option < String > ,
29- pub ( crate ) backtrace : Option < String > , // Only used if STORE_STACK_TRACES is true
29+ pub ( crate ) backtrace : Option < backtrace :: Backtrace > , // Only used if STORE_STACK_TRACES is true
3030 next : Option < std:: num:: NonZeroU64 > ,
3131 prev : Option < std:: num:: NonZeroU64 > ,
3232}
@@ -156,7 +156,7 @@ impl SubAllocator for FreeListAllocator {
156156 allocation_type : AllocationType ,
157157 granularity : u64 ,
158158 name : & str ,
159- backtrace : Option < & str > ,
159+ backtrace : Option < backtrace :: Backtrace > ,
160160 ) -> Result < ( u64 , std:: num:: NonZeroU64 ) > {
161161 let free_size = self . size - self . allocated ;
162162 if size > free_size {
@@ -243,7 +243,7 @@ impl SubAllocator for FreeListAllocator {
243243 offset : free_chunk. offset ,
244244 allocation_type,
245245 name : Some ( name. to_string ( ) ) ,
246- backtrace : backtrace . map ( |s| s . to_owned ( ) ) ,
246+ backtrace,
247247 prev : free_chunk. prev ,
248248 next : Some ( first_fit_id) ,
249249 } ;
@@ -272,7 +272,7 @@ impl SubAllocator for FreeListAllocator {
272272
273273 chunk. allocation_type = allocation_type;
274274 chunk. name = Some ( name. to_string ( ) ) ;
275- chunk. backtrace = backtrace. map ( |s| s . to_owned ( ) ) ;
275+ chunk. backtrace = backtrace;
276276
277277 self . remove_id_from_free_list ( first_fit_id) ;
278278
@@ -356,7 +356,7 @@ impl SubAllocator for FreeListAllocator {
356356 }
357357 let empty = "" . to_string ( ) ;
358358 let name = chunk. name . as_ref ( ) . unwrap_or ( & empty) ;
359- let backtrace = chunk. backtrace . as_ref ( ) . unwrap_or ( & empty ) ;
359+ let backtrace = resolve_backtrace ( & chunk. backtrace ) ;
360360
361361 log ! (
362362 log_level,
@@ -383,12 +383,30 @@ impl SubAllocator for FreeListAllocator {
383383 ) ;
384384 }
385385 }
386+
387+ fn report_allocations ( & self ) -> Vec < AllocationReport > {
388+ self . chunks
389+ . iter ( )
390+ . filter ( |( _key, chunk) | chunk. allocation_type != AllocationType :: Free )
391+ . map ( |( _key, chunk) | AllocationReport {
392+ name : chunk
393+ . name
394+ . clone ( )
395+ . unwrap_or_else ( || "<Unnamed FreeList allocation>" . to_owned ( ) ) ,
396+ size : chunk. size ,
397+ backtrace : chunk. backtrace . clone ( ) ,
398+ } )
399+ . collect :: < Vec < _ > > ( )
400+ }
401+
386402 fn size ( & self ) -> u64 {
387403 self . size
388404 }
405+
389406 fn allocated ( & self ) -> u64 {
390407 self . allocated
391408 }
409+
392410 fn supports_general_allocations ( & self ) -> bool {
393411 true
394412 }
0 commit comments