@@ -295,9 +295,10 @@ fn write_flamegraph<'a, I: IntoIterator<Item = &'a str>>(
295
295
296
296
#[ cfg( test) ]
297
297
mod tests {
298
- use super :: { AllocationTracker , Callstack } ;
298
+ use super :: { AllocationTracker , CallSite , Callstack } ;
299
299
use itertools:: Itertools ;
300
300
use proptest:: prelude:: * ;
301
+ use smallstr:: SmallString ;
301
302
use std:: collections;
302
303
303
304
proptest ! {
@@ -356,19 +357,31 @@ mod tests {
356
357
#[ test]
357
358
fn combine_callstacks_and_sum_allocations ( ) {
358
359
let mut tracker = AllocationTracker :: new ( ) ;
360
+ let id1 = tracker. call_sites . get_or_insert_id ( CallSite {
361
+ module_name : SmallString :: from_str ( "a" ) ,
362
+ function_name : SmallString :: from_str ( "af" ) ,
363
+ } ) ;
364
+ let id2 = tracker. call_sites . get_or_insert_id ( CallSite {
365
+ module_name : SmallString :: from_str ( "b" ) ,
366
+ function_name : SmallString :: from_str ( "bf" ) ,
367
+ } ) ;
368
+ let id3 = tracker. call_sites . get_or_insert_id ( CallSite {
369
+ module_name : SmallString :: from_str ( "c" ) ,
370
+ function_name : SmallString :: from_str ( "cf" ) ,
371
+ } ) ;
359
372
let mut cs1 = Callstack :: new ( ) ;
360
- cs1. start_call ( 1 ) ;
361
- cs1. start_call ( 2 ) ;
373
+ cs1. start_call ( id1 ) ;
374
+ cs1. start_call ( id2 ) ;
362
375
let mut cs2 = Callstack :: new ( ) ;
363
- cs2. start_call ( 3 ) ;
376
+ cs2. start_call ( id3 ) ;
364
377
365
378
tracker. add_allocation ( 1 , 1000 , cs1. clone ( ) ) ;
366
379
tracker. add_allocation ( 2 , 234 , cs2. clone ( ) ) ;
367
380
tracker. add_allocation ( 3 , 50000 , cs1. clone ( ) ) ;
368
381
369
382
let mut expected: collections:: HashMap < String , usize > = collections:: HashMap :: new ( ) ;
370
- expected. insert ( "a;b " . to_string ( ) , 51000 ) ;
371
- expected. insert ( "c" . to_string ( ) , 234 ) ;
383
+ expected. insert ( "a:af;b:bf " . to_string ( ) , 51000 ) ;
384
+ expected. insert ( "c:cf " . to_string ( ) , 234 ) ;
372
385
assert_eq ! ( expected, tracker. combine_callstacks( ) ) ;
373
386
}
374
387
}
0 commit comments