@@ -269,6 +269,7 @@ struct TrackedConsumer {
269
269
name : String ,
270
270
can_spill : bool ,
271
271
reserved : AtomicUsize ,
272
+ peak : AtomicUsize ,
272
273
}
273
274
274
275
impl TrackedConsumer {
@@ -277,10 +278,16 @@ impl TrackedConsumer {
277
278
self . reserved . load ( Ordering :: Relaxed )
278
279
}
279
280
281
+ /// Return the peak value
282
+ fn peak ( & self ) -> usize {
283
+ self . peak . load ( Ordering :: Relaxed )
284
+ }
285
+
280
286
/// Grows the tracked consumer's reserved size,
281
287
/// should be called after the pool has successfully performed the grow().
282
288
fn grow ( & self , additional : usize ) {
283
289
self . reserved . fetch_add ( additional, Ordering :: Relaxed ) ;
290
+ self . peak . fetch_max ( self . reserved ( ) , Ordering :: Relaxed ) ;
284
291
}
285
292
286
293
/// Reduce the tracked consumer's reserved size,
@@ -379,6 +386,7 @@ impl<I: MemoryPool> TrackConsumersPool<I> {
379
386
* consumer_id,
380
387
tracked_consumer. name . to_owned ( ) ,
381
388
tracked_consumer. can_spill ,
389
+ tracked_consumer. peak ( ) ,
382
390
) ,
383
391
tracked_consumer. reserved ( ) ,
384
392
)
@@ -388,10 +396,11 @@ impl<I: MemoryPool> TrackConsumersPool<I> {
388
396
389
397
consumers[ 0 ..std:: cmp:: min ( top, consumers. len ( ) ) ]
390
398
. iter ( )
391
- . map ( |( ( id, name, can_spill) , size) | {
399
+ . map ( |( ( id, name, can_spill, peak ) , size) | {
392
400
format ! (
393
- " {name}#{id}(can spill: {can_spill}) consumed {}" ,
394
- human_readable_size( * size)
401
+ " {name}#{id}(can spill: {can_spill}) consumed {}, peak {}" ,
402
+ human_readable_size( * size) ,
403
+ human_readable_size( * peak) ,
395
404
)
396
405
} )
397
406
. collect :: < Vec < _ > > ( )
@@ -411,6 +420,7 @@ impl<I: MemoryPool> MemoryPool for TrackConsumersPool<I> {
411
420
name : consumer. name ( ) . to_string ( ) ,
412
421
can_spill : consumer. can_spill ( ) ,
413
422
reserved : Default :: default ( ) ,
423
+ peak : Default :: default ( ) ,
414
424
} ,
415
425
) ;
416
426
@@ -581,7 +591,8 @@ mod tests {
581
591
582
592
// set r1=50, using grow and shrink
583
593
let mut r1 = MemoryConsumer :: new ( "r1" ) . register ( & pool) ;
584
- r1. grow ( 70 ) ;
594
+ r1. grow ( 50 ) ;
595
+ r1. grow ( 20 ) ;
585
596
r1. shrink ( 20 ) ;
586
597
587
598
// set r2=15 using try_grow
@@ -609,9 +620,9 @@ mod tests {
609
620
let error = res. unwrap_err ( ) . strip_backtrace ( ) ;
610
621
assert_snapshot ! ( error, @r"
611
622
Resources exhausted: Additional allocation failed with top memory consumers (across reservations) as:
612
- r1#[ID](can spill: false) consumed 50.0 B,
613
- r3#[ID](can spill: false) consumed 20.0 B,
614
- r2#[ID](can spill: false) consumed 15.0 B.
623
+ r1#[ID](can spill: false) consumed 50.0 B, peak 70.0 B,
624
+ r3#[ID](can spill: false) consumed 20.0 B, peak 25.0 B,
625
+ r2#[ID](can spill: false) consumed 15.0 B, peak 15.0 B .
615
626
Error: Failed to allocate additional 150.0 B for r5 with 0.0 B already allocated for this reservation - 5.0 B remain available for the total pool
616
627
" ) ;
617
628
}
@@ -634,7 +645,7 @@ mod tests {
634
645
let error = res. unwrap_err ( ) . strip_backtrace ( ) ;
635
646
assert_snapshot ! ( error, @r"
636
647
Resources exhausted: Additional allocation failed with top memory consumers (across reservations) as:
637
- foo#[ID](can spill: false) consumed 0.0 B.
648
+ foo#[ID](can spill: false) consumed 0.0 B, peak 0.0 B .
638
649
Error: Failed to allocate additional 150.0 B for foo with 0.0 B already allocated for this reservation - 100.0 B remain available for the total pool
639
650
" ) ;
640
651
@@ -651,8 +662,8 @@ mod tests {
651
662
let error = res. unwrap_err ( ) . strip_backtrace ( ) ;
652
663
assert_snapshot ! ( error, @r"
653
664
Resources exhausted: Additional allocation failed with top memory consumers (across reservations) as:
654
- foo#[ID](can spill: false) consumed 10.0 B,
655
- foo#[ID](can spill: false) consumed 0.0 B.
665
+ foo#[ID](can spill: false) consumed 10.0 B, peak 10.0 B,
666
+ foo#[ID](can spill: false) consumed 0.0 B, peak 0.0 B .
656
667
Error: Failed to allocate additional 150.0 B for foo with 0.0 B already allocated for this reservation - 90.0 B remain available for the total pool
657
668
" ) ;
658
669
@@ -664,8 +675,8 @@ mod tests {
664
675
let error = res. unwrap_err ( ) . strip_backtrace ( ) ;
665
676
assert_snapshot ! ( error, @r"
666
677
Resources exhausted: Additional allocation failed with top memory consumers (across reservations) as:
667
- foo#[ID](can spill: false) consumed 20.0 B,
668
- foo#[ID](can spill: false) consumed 10.0 B.
678
+ foo#[ID](can spill: false) consumed 20.0 B, peak 20.0 B,
679
+ foo#[ID](can spill: false) consumed 10.0 B, peak 10.0 B .
669
680
Error: Failed to allocate additional 150.0 B for foo with 20.0 B already allocated for this reservation - 70.0 B remain available for the total pool
670
681
" ) ;
671
682
@@ -679,9 +690,9 @@ mod tests {
679
690
let error = res. unwrap_err ( ) . strip_backtrace ( ) ;
680
691
assert_snapshot ! ( error, @r"
681
692
Resources exhausted: Additional allocation failed with top memory consumers (across reservations) as:
682
- foo#[ID](can spill: false) consumed 20.0 B,
683
- foo#[ID](can spill: false) consumed 10.0 B,
684
- foo#[ID](can spill: true) consumed 0.0 B.
693
+ foo#[ID](can spill: false) consumed 20.0 B, peak 20.0 B,
694
+ foo#[ID](can spill: false) consumed 10.0 B, peak 10.0 B,
695
+ foo#[ID](can spill: true) consumed 0.0 B, peak 0.0 B .
685
696
Error: Failed to allocate additional 150.0 B for foo with 0.0 B already allocated for this reservation - 70.0 B remain available for the total pool
686
697
" ) ;
687
698
}
@@ -703,8 +714,8 @@ mod tests {
703
714
let error = res. unwrap_err ( ) . strip_backtrace ( ) ;
704
715
allow_duplicates ! ( assert_snapshot!( error, @r"
705
716
Resources exhausted: Additional allocation failed with top memory consumers (across reservations) as:
706
- r1#[ID](can spill: false) consumed 20.0 B,
707
- r0#[ID](can spill: false) consumed 10.0 B.
717
+ r1#[ID](can spill: false) consumed 20.0 B, peak 20.0 B,
718
+ r0#[ID](can spill: false) consumed 10.0 B, peak 10.0 B .
708
719
Error: Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 70.0 B remain available for the total pool
709
720
" ) ) ;
710
721
@@ -716,7 +727,7 @@ mod tests {
716
727
let error = res. unwrap_err ( ) . strip_backtrace ( ) ;
717
728
allow_duplicates ! ( assert_snapshot!( error, @r"
718
729
Resources exhausted: Additional allocation failed with top memory consumers (across reservations) as:
719
- r0#[ID](can spill: false) consumed 10.0 B.
730
+ r0#[ID](can spill: false) consumed 10.0 B, peak 10.0 B .
720
731
Error: Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 90.0 B remain available for the total pool
721
732
" ) ) ;
722
733
@@ -727,7 +738,7 @@ mod tests {
727
738
let error = res. unwrap_err ( ) . strip_backtrace ( ) ;
728
739
allow_duplicates ! ( assert_snapshot!( error, @r"
729
740
Resources exhausted: Additional allocation failed with top memory consumers (across reservations) as:
730
- r0#[ID](can spill: false) consumed 10.0 B.
741
+ r0#[ID](can spill: false) consumed 10.0 B, peak 10.0 B .
731
742
Error: Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 90.0 B remain available for the total pool
732
743
" ) ) ;
733
744
@@ -738,7 +749,7 @@ mod tests {
738
749
let error = res. unwrap_err ( ) . strip_backtrace ( ) ;
739
750
allow_duplicates ! ( assert_snapshot!( error, @r"
740
751
Resources exhausted: Additional allocation failed with top memory consumers (across reservations) as:
741
- r0#[ID](can spill: false) consumed 10.0 B.
752
+ r0#[ID](can spill: false) consumed 10.0 B, peak 10.0 B .
742
753
Error: Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 90.0 B remain available for the total pool
743
754
" ) ) ;
744
755
}
@@ -785,8 +796,8 @@ mod tests {
785
796
// Test: can get runtime metrics, even without an error thrown
786
797
let res = downcasted. report_top ( 2 ) ;
787
798
assert_snapshot ! ( res, @r"
788
- r3#[ID](can spill: false) consumed 45.0 B,
789
- r1#[ID](can spill: false) consumed 20.0 B.
799
+ r3#[ID](can spill: false) consumed 45.0 B, peak 45.0 B,
800
+ r1#[ID](can spill: false) consumed 20.0 B, peak 20.0 B .
790
801
" ) ;
791
802
}
792
803
}
0 commit comments