@@ -555,13 +555,16 @@ impl<'a> TimingGuard<'a> {
555
555
556
556
#[ must_use]
557
557
pub struct VerboseTimingGuard < ' a > {
558
- start_and_message : Option < ( Instant , String ) > ,
558
+ start_and_message : Option < ( Instant , Option < usize > , String ) > ,
559
559
_guard : TimingGuard < ' a > ,
560
560
}
561
561
562
562
impl < ' a > VerboseTimingGuard < ' a > {
563
563
pub fn start ( message : Option < String > , _guard : TimingGuard < ' a > ) -> Self {
564
- VerboseTimingGuard { _guard, start_and_message : message. map ( |msg| ( Instant :: now ( ) , msg) ) }
564
+ VerboseTimingGuard {
565
+ _guard,
566
+ start_and_message : message. map ( |msg| ( Instant :: now ( ) , get_resident_set_size ( ) , msg) ) ,
567
+ }
565
568
}
566
569
567
570
#[ inline( always) ]
@@ -573,25 +576,42 @@ impl<'a> VerboseTimingGuard<'a> {
573
576
574
577
impl Drop for VerboseTimingGuard < ' _ > {
575
578
fn drop ( & mut self ) {
576
- if let Some ( ( start, ref message) ) = self . start_and_message {
577
- print_time_passes_entry ( true , & message[ ..] , start. elapsed ( ) ) ;
579
+ if let Some ( ( start_time, start_rss, ref message) ) = self . start_and_message {
580
+ let end_rss = get_resident_set_size ( ) ;
581
+ print_time_passes_entry ( & message[ ..] , start_time. elapsed ( ) , start_rss, end_rss) ;
578
582
}
579
583
}
580
584
}
581
585
582
- pub fn print_time_passes_entry ( do_it : bool , what : & str , dur : Duration ) {
583
- if !do_it {
584
- return ;
585
- }
586
-
587
- let mem_string = match get_resident ( ) {
588
- Some ( n) => {
589
- let mb = n as f64 / 1_000_000.0 ;
590
- format ! ( "; rss: {}MB" , mb. round( ) as usize )
586
+ pub fn print_time_passes_entry (
587
+ what : & str ,
588
+ dur : Duration ,
589
+ start_rss : Option < usize > ,
590
+ end_rss : Option < usize > ,
591
+ ) {
592
+ let rss_to_mb = |rss| ( rss as f64 / 1_000_000.0 ) . round ( ) as usize ;
593
+
594
+ let mem_string = match ( start_rss, end_rss) {
595
+ ( Some ( start_rss) , Some ( end_rss) ) => {
596
+ // It's tempting to add the change in RSS from start to end, but its somewhat confusing
597
+ // and misleading when looking at time-passes output. Consider two adjacent entries:
598
+ //
599
+ // time: 10.000; rss start: 1000MB, end: 1000MB, change: 0MB pass1
600
+ // time: 5.000; rss start: 2000MB, end: 2000MB, change: 0MB pass2
601
+ //
602
+ // If you're looking for jumps in RSS based on the change column, you miss the fact
603
+ // that a 1GB jump happened between pass1 and pass2 (supposing pass1 and pass2 actually
604
+ // occur sequentially and pass1 isn't just nested within pass2). It's easy to imagine
605
+ // someone missing this or being confused by the fact that the change is zero.
606
+
607
+ format ! ( "; rss: {:>5}MB -> {:>5}MB" , rss_to_mb( start_rss) , rss_to_mb( end_rss) )
591
608
}
592
- None => String :: new ( ) ,
609
+ ( Some ( start_rss) , None ) => format ! ( "; rss start: {:>5}MB" , rss_to_mb( start_rss) ) ,
610
+ ( None , Some ( end_rss) ) => format ! ( "; rss end: {:5>}MB" , rss_to_mb( end_rss) ) ,
611
+ ( None , None ) => String :: new ( ) ,
593
612
} ;
594
- println ! ( "time: {}{}\t {}" , duration_to_secs_str( dur) , mem_string, what) ;
613
+
614
+ println ! ( "time: {:>7}{}\t {}" , duration_to_secs_str( dur) , mem_string, what) ;
595
615
}
596
616
597
617
// Hack up our own formatting for the duration to make it easier for scripts
@@ -603,7 +623,7 @@ pub fn duration_to_secs_str(dur: std::time::Duration) -> String {
603
623
// Memory reporting
604
624
cfg_if ! {
605
625
if #[ cfg( windows) ] {
606
- fn get_resident ( ) -> Option <usize > {
626
+ pub fn get_resident_set_size ( ) -> Option <usize > {
607
627
use std:: mem:: { self , MaybeUninit } ;
608
628
use winapi:: shared:: minwindef:: DWORD ;
609
629
use winapi:: um:: processthreadsapi:: GetCurrentProcess ;
@@ -621,7 +641,7 @@ cfg_if! {
621
641
}
622
642
}
623
643
} else if #[ cfg( unix) ] {
624
- fn get_resident ( ) -> Option <usize > {
644
+ pub fn get_resident_set_size ( ) -> Option <usize > {
625
645
let field = 1 ;
626
646
let contents = fs:: read( "/proc/self/statm" ) . ok( ) ?;
627
647
let contents = String :: from_utf8( contents) . ok( ) ?;
@@ -630,7 +650,7 @@ cfg_if! {
630
650
Some ( npages * 4096 )
631
651
}
632
652
} else {
633
- fn get_resident ( ) -> Option <usize > {
653
+ pub fn get_resident_set_size ( ) -> Option <usize > {
634
654
None
635
655
}
636
656
}
0 commit comments