33
44use std:: {
55 path:: Path ,
6- time:: { Instant , SystemTime , UNIX_EPOCH } ,
6+ time:: { SystemTime , UNIX_EPOCH } ,
77} ;
88
99use hir:: {
@@ -29,6 +29,7 @@ use crate::{
2929 } ,
3030 print_memory_usage,
3131} ;
32+ use ra_prof:: StopWatch ;
3233
3334/// Need to wrap Snapshot to provide `Clone` impl for `map_with`
3435struct Snap < DB > ( DB ) ;
@@ -54,11 +55,12 @@ pub fn analysis_stats(
5455 Rand32 :: new ( seed)
5556 } ;
5657
57- let db_load_time = Instant :: now ( ) ;
58+ let mut db_load_sw = StopWatch :: start ( ) . memory ( memory_usage ) ;
5859 let ( host, vfs) = load_cargo ( path, load_output_dirs, with_proc_macro) ?;
5960 let db = host. raw_database ( ) ;
60- eprintln ! ( "Database loaded {:?}" , db_load_time. elapsed( ) ) ;
61- let analysis_time = Instant :: now ( ) ;
61+ eprintln ! ( "Database loaded {}" , db_load_sw. elapsed( ) ) ;
62+
63+ let mut analysis_sw = StopWatch :: start ( ) . memory ( memory_usage) ;
6264 let mut num_crates = 0 ;
6365 let mut visited_modules = FxHashSet :: default ( ) ;
6466 let mut visit_queue = Vec :: new ( ) ;
@@ -110,20 +112,20 @@ pub fn analysis_stats(
110112 eprintln ! ( "Total modules found: {}" , visited_modules. len( ) ) ;
111113 eprintln ! ( "Total declarations: {}" , num_decls) ;
112114 eprintln ! ( "Total functions: {}" , funcs. len( ) ) ;
113- let item_collection_memory = ra_prof:: memory_usage ( ) ;
114- eprintln ! ( "Item Collection: {:?}, {}" , analysis_time. elapsed( ) , item_collection_memory) ;
115+ eprintln ! ( "Item Collection: {}" , analysis_sw. elapsed( ) ) ;
115116
116117 if randomize {
117118 shuffle ( & mut rng, & mut funcs) ;
118119 }
119120
120121 let mut bar = match verbosity {
121122 Verbosity :: Quiet | Verbosity :: Spammy => ProgressReport :: hidden ( ) ,
123+ _ if parallel => ProgressReport :: hidden ( ) ,
122124 _ => ProgressReport :: new ( funcs. len ( ) as u64 ) ,
123125 } ;
124126
125127 if parallel {
126- let inference_time = Instant :: now ( ) ;
128+ let mut inference_sw = StopWatch :: start ( ) . memory ( memory_usage ) ;
127129 let snap = Snap ( db. snapshot ( ) ) ;
128130 funcs
129131 . par_iter ( )
@@ -133,14 +135,10 @@ pub fn analysis_stats(
133135 snap. 0 . infer ( f_id. into ( ) ) ;
134136 } )
135137 . count ( ) ;
136- eprintln ! (
137- "Parallel Inference: {:?}, {}" ,
138- inference_time. elapsed( ) ,
139- ra_prof:: memory_usage( )
140- ) ;
138+ eprintln ! ( "Parallel Inference: {}" , inference_sw. elapsed( ) ) ;
141139 }
142140
143- let inference_time = Instant :: now ( ) ;
141+ let mut inference_sw = StopWatch :: start ( ) . memory ( memory_usage ) ;
144142 bar. tick ( ) ;
145143 let mut num_exprs = 0 ;
146144 let mut num_exprs_unknown = 0 ;
@@ -291,14 +289,17 @@ pub fn analysis_stats(
291289 eprintln ! ( "Type mismatches: {}" , num_type_mismatches) ;
292290 report_metric ( "type mismatches" , num_type_mismatches, "#" ) ;
293291
294- let inference_time = inference_time. elapsed ( ) ;
295- let total_memory = ra_prof:: memory_usage ( ) ;
296- eprintln ! ( "Inference: {:?}, {}" , inference_time, total_memory - item_collection_memory) ;
292+ eprintln ! ( "Inference: {}" , inference_sw. elapsed( ) ) ;
297293
298- let analysis_time = analysis_time. elapsed ( ) ;
299- eprintln ! ( "Total: {:?}, {}" , analysis_time, total_memory) ;
300- report_metric ( "total time" , analysis_time. as_millis ( ) as u64 , "ms" ) ;
301- report_metric ( "total memory" , total_memory. allocated . megabytes ( ) as u64 , "MB" ) ;
294+ let total_span = analysis_sw. elapsed ( ) ;
295+ eprintln ! ( "Total: {}" , total_span) ;
296+ report_metric ( "total time" , total_span. time . as_millis ( ) as u64 , "ms" ) ;
297+ if let Some ( instructions) = total_span. instructions {
298+ report_metric ( "total time" , instructions, "#instr" ) ;
299+ }
300+ if let Some ( memory) = total_span. memory {
301+ report_metric ( "total memory" , memory. allocated . megabytes ( ) as u64 , "MB" ) ;
302+ }
302303
303304 if memory_usage {
304305 print_memory_usage ( host, vfs) ;
0 commit comments