33
44use std:: { path:: Path , time:: Instant } ;
55
6- use itertools:: Itertools ;
7- use rand:: { seq:: SliceRandom , thread_rng} ;
8- use rayon:: prelude:: * ;
9- use rustc_hash:: FxHashSet ;
10-
116use hir:: {
127 db:: { AstDatabase , DefDatabase , HirDatabase } ,
138 original_range, AssocItem , Crate , HasSource , HirDisplay , ModuleDef ,
149} ;
1510use hir_def:: FunctionId ;
1611use hir_ty:: { Ty , TypeWalk } ;
12+ use itertools:: Itertools ;
1713use ra_db:: {
1814 salsa:: { self , ParallelDatabase } ,
1915 SourceDatabaseExt ,
2016} ;
2117use ra_syntax:: AstNode ;
18+ use rand:: { seq:: SliceRandom , thread_rng} ;
19+ use rayon:: prelude:: * ;
20+ use rustc_hash:: FxHashSet ;
2221use stdx:: format_to;
2322
2423use crate :: {
25- cli:: { load_cargo:: load_cargo, progress_report:: ProgressReport , Result , Verbosity } ,
24+ cli:: {
25+ load_cargo:: load_cargo, progress_report:: ProgressReport , report_metric, Result , Verbosity ,
26+ } ,
2627 print_memory_usage,
2728} ;
2829
@@ -48,7 +49,7 @@ pub fn analysis_stats(
4849 let db_load_time = Instant :: now ( ) ;
4950 let ( host, vfs) = load_cargo ( path, load_output_dirs, with_proc_macro) ?;
5051 let db = host. raw_database ( ) ;
51- println ! ( "Database loaded {:?}" , db_load_time. elapsed( ) ) ;
52+ eprintln ! ( "Database loaded {:?}" , db_load_time. elapsed( ) ) ;
5253 let analysis_time = Instant :: now ( ) ;
5354 let mut num_crates = 0 ;
5455 let mut visited_modules = FxHashSet :: default ( ) ;
@@ -74,7 +75,7 @@ pub fn analysis_stats(
7475 visit_queue. shuffle ( & mut thread_rng ( ) ) ;
7576 }
7677
77- println ! ( "Crates in this dir: {}" , num_crates) ;
78+ eprintln ! ( "Crates in this dir: {}" , num_crates) ;
7879 let mut num_decls = 0 ;
7980 let mut funcs = Vec :: new ( ) ;
8081 while let Some ( module) = visit_queue. pop ( ) {
@@ -98,10 +99,15 @@ pub fn analysis_stats(
9899 }
99100 }
100101 }
101- println ! ( "Total modules found: {}" , visited_modules. len( ) ) ;
102- println ! ( "Total declarations: {}" , num_decls) ;
103- println ! ( "Total functions: {}" , funcs. len( ) ) ;
104- println ! ( "Item Collection: {:?}, {}" , analysis_time. elapsed( ) , ra_prof:: memory_usage( ) ) ;
102+ eprintln ! ( "Total modules found: {}" , visited_modules. len( ) ) ;
103+ eprintln ! ( "Total declarations: {}" , num_decls) ;
104+ eprintln ! ( "Total functions: {}" , funcs. len( ) ) ;
105+ let item_collection_memory = ra_prof:: memory_usage ( ) ;
106+ eprintln ! (
107+ "Item Collection: {:?}, {}" ,
108+ analysis_time. elapsed( ) ,
109+ item_collection_memory. allocated
110+ ) ;
105111
106112 if randomize {
107113 funcs. shuffle ( & mut thread_rng ( ) ) ;
@@ -123,7 +129,11 @@ pub fn analysis_stats(
123129 snap. 0 . infer ( f_id. into ( ) ) ;
124130 } )
125131 . count ( ) ;
126- println ! ( "Parallel Inference: {:?}, {}" , inference_time. elapsed( ) , ra_prof:: memory_usage( ) ) ;
132+ eprintln ! (
133+ "Parallel Inference: {:?}, {}" ,
134+ inference_time. elapsed( ) ,
135+ ra_prof:: memory_usage( ) . allocated
136+ ) ;
127137 }
128138
129139 let inference_time = Instant :: now ( ) ;
@@ -260,20 +270,31 @@ pub fn analysis_stats(
260270 bar. inc ( 1 ) ;
261271 }
262272 bar. finish_and_clear ( ) ;
263- println ! ( "Total expressions: {}" , num_exprs) ;
264- println ! (
273+ eprintln ! ( "Total expressions: {}" , num_exprs) ;
274+ eprintln ! (
265275 "Expressions of unknown type: {} ({}%)" ,
266276 num_exprs_unknown,
267277 if num_exprs > 0 { num_exprs_unknown * 100 / num_exprs } else { 100 }
268278 ) ;
269- println ! (
279+ eprintln ! (
270280 "Expressions of partially unknown type: {} ({}%)" ,
271281 num_exprs_partially_unknown,
272282 if num_exprs > 0 { num_exprs_partially_unknown * 100 / num_exprs } else { 100 }
273283 ) ;
274- println ! ( "Type mismatches: {}" , num_type_mismatches) ;
275- println ! ( "Inference: {:?}, {}" , inference_time. elapsed( ) , ra_prof:: memory_usage( ) ) ;
276- println ! ( "Total: {:?}, {}" , analysis_time. elapsed( ) , ra_prof:: memory_usage( ) ) ;
284+ eprintln ! ( "Type mismatches: {}" , num_type_mismatches) ;
285+
286+ let inference_time = inference_time. elapsed ( ) ;
287+ let total_memory = ra_prof:: memory_usage ( ) ;
288+ eprintln ! (
289+ "Inference: {:?}, {}" ,
290+ inference_time,
291+ total_memory. allocated - item_collection_memory. allocated
292+ ) ;
293+
294+ let analysis_time = analysis_time. elapsed ( ) ;
295+ eprintln ! ( "Total: {:?}, {}" , analysis_time, total_memory) ;
296+ report_metric ( "total time" , analysis_time. as_millis ( ) as u64 , "ms" ) ;
297+ report_metric ( "total memory" , total_memory. allocated . megabytes ( ) as u64 , "MB" ) ;
277298
278299 if memory_usage {
279300 print_memory_usage ( host, vfs) ;
0 commit comments