@@ -14,16 +14,17 @@ use hir_def::{body::BodySourceMap, expr::ExprId, FunctionId};
14
14
use hir_ty:: { TyExt , TypeWalk } ;
15
15
use ide:: { Analysis , AnalysisHost , LineCol , RootDatabase } ;
16
16
use ide_db:: base_db:: {
17
- salsa:: { self , ParallelDatabase } ,
18
- SourceDatabaseExt ,
17
+ salsa:: { self , debug :: DebugQueryTable , ParallelDatabase } ,
18
+ SourceDatabase , SourceDatabaseExt ,
19
19
} ;
20
20
use itertools:: Itertools ;
21
21
use oorandom:: Rand32 ;
22
+ use profile:: { Bytes , StopWatch } ;
22
23
use project_model:: CargoConfig ;
23
24
use rayon:: prelude:: * ;
24
25
use rustc_hash:: FxHashSet ;
25
26
use stdx:: format_to;
26
- use syntax:: AstNode ;
27
+ use syntax:: { AstNode , SyntaxNode } ;
27
28
use vfs:: { Vfs , VfsPath } ;
28
29
29
30
use crate :: cli:: {
@@ -33,7 +34,6 @@ use crate::cli::{
33
34
progress_report:: ProgressReport ,
34
35
report_metric, Result , Verbosity ,
35
36
} ;
36
- use profile:: StopWatch ;
37
37
38
38
/// Need to wrap Snapshot to provide `Clone` impl for `map_with`
39
39
struct Snap < DB > ( DB ) ;
@@ -137,6 +137,21 @@ impl flags::AnalysisStats {
137
137
eprintln ! ( "{}" , profile:: countme:: get_all( ) ) ;
138
138
}
139
139
140
+ if self . source_stats {
141
+ let mut total_file_size = Bytes :: default ( ) ;
142
+ for e in ide_db:: base_db:: ParseQuery . in_db ( db) . entries :: < Vec < _ > > ( ) {
143
+ total_file_size += syntax_len ( db. parse ( e. key ) . syntax_node ( ) )
144
+ }
145
+
146
+ let mut total_macro_file_size = Bytes :: default ( ) ;
147
+ for e in hir:: db:: ParseMacroExpansionQuery . in_db ( db) . entries :: < Vec < _ > > ( ) {
148
+ if let Some ( ( val, _) ) = db. parse_macro_expansion ( e. key ) . value {
149
+ total_macro_file_size += syntax_len ( val. syntax_node ( ) )
150
+ }
151
+ }
152
+ eprintln ! ( "source files: {}, macro files: {}" , total_file_size, total_macro_file_size) ;
153
+ }
154
+
140
155
if self . memory_usage && verbosity. is_verbose ( ) {
141
156
print_memory_usage ( host, vfs) ;
142
157
}
@@ -361,3 +376,9 @@ fn shuffle<T>(rng: &mut Rand32, slice: &mut [T]) {
361
376
fn percentage ( n : u64 , total : u64 ) -> u64 {
362
377
( n * 100 ) . checked_div ( total) . unwrap_or ( 100 )
363
378
}
379
+
380
+ fn syntax_len ( node : SyntaxNode ) -> usize {
381
+ // Macro expanded code doesn't contain whitespace, so erase *all* whitespace
382
+ // to make macro and non-macro code comparable.
383
+ node. to_string ( ) . replace ( |it : char | it. is_ascii_whitespace ( ) , "" ) . len ( )
384
+ }
0 commit comments