33
44use std:: {
55 env, fmt,
6+ ops:: AddAssign ,
67 time:: { SystemTime , UNIX_EPOCH } ,
78} ;
89
@@ -125,6 +126,9 @@ impl flags::AnalysisStats {
125126 let mut dep_item_trees = 0 ;
126127 let mut workspace_item_trees = 0 ;
127128
129+ let mut workspace_item_stats = PrettyItemStats :: default ( ) ;
130+ let mut dep_item_stats = PrettyItemStats :: default ( ) ;
131+
128132 for source_root_id in source_roots {
129133 let source_root = db. source_root ( source_root_id) . source_root ( db) ;
130134 for file_id in source_root. iter ( ) {
@@ -133,16 +137,24 @@ impl flags::AnalysisStats {
133137 // measure workspace/project code
134138 if !source_root. is_library || self . with_deps {
135139 let length = db. file_text ( file_id) . text ( db) . lines ( ) . count ( ) ;
136- db. file_item_tree ( EditionedFileId :: current_edition ( file_id) . into ( ) ) ;
140+ let item_stats = db
141+ . file_item_tree ( EditionedFileId :: current_edition ( file_id) . into ( ) )
142+ . item_tree_stats ( )
143+ . into ( ) ;
137144
138145 workspace_loc += length;
139146 workspace_item_trees += 1 ;
147+ workspace_item_stats += item_stats;
140148 } else {
141149 let length = db. file_text ( file_id) . text ( db) . lines ( ) . count ( ) ;
142- db. file_item_tree ( EditionedFileId :: current_edition ( file_id) . into ( ) ) ;
150+ let item_stats = db
151+ . file_item_tree ( EditionedFileId :: current_edition ( file_id) . into ( ) )
152+ . item_tree_stats ( )
153+ . into ( ) ;
143154
144155 dep_loc += length;
145- dep_item_trees += 1
156+ dep_item_trees += 1 ;
157+ dep_item_stats += item_stats;
146158 }
147159 }
148160 }
@@ -157,11 +169,13 @@ impl flags::AnalysisStats {
157169 UsizeWithUnderscore ( dep_loc) ,
158170 UsizeWithUnderscore ( dep_item_trees) ,
159171 ) ;
172+ eprintln ! ( " dependency item stats: {}" , dep_item_stats) ;
160173 eprintln ! (
161174 " workspace lines of code: {}, item trees: {}" ,
162175 UsizeWithUnderscore ( workspace_loc) ,
163176 UsizeWithUnderscore ( workspace_item_trees) ,
164177 ) ;
178+ eprintln ! ( " workspace stats: {}" , workspace_item_stats) ;
165179
166180 // FIXME(salsa-transition): bring back stats for ParseQuery (file size)
167181 // and ParseMacroExpansionQuery (macro expansion "file") size whenever we implement
@@ -1251,6 +1265,7 @@ fn percentage(n: u64, total: u64) -> u64 {
12511265 ( n * 100 ) . checked_div ( total) . unwrap_or ( 100 )
12521266}
12531267
1268+ #[ derive( Default , Debug , Eq , PartialEq ) ]
12541269struct UsizeWithUnderscore ( usize ) ;
12551270
12561271impl fmt:: Display for UsizeWithUnderscore {
@@ -1275,6 +1290,53 @@ impl fmt::Display for UsizeWithUnderscore {
12751290 }
12761291}
12771292
1293+ impl std:: ops:: AddAssign for UsizeWithUnderscore {
1294+ fn add_assign ( & mut self , other : UsizeWithUnderscore ) {
1295+ self . 0 += other. 0 ;
1296+ }
1297+ }
1298+
1299+ #[ derive( Default , Debug , Eq , PartialEq ) ]
1300+ struct PrettyItemStats {
1301+ traits : UsizeWithUnderscore ,
1302+ impls : UsizeWithUnderscore ,
1303+ mods : UsizeWithUnderscore ,
1304+ macro_calls : UsizeWithUnderscore ,
1305+ macro_rules : UsizeWithUnderscore ,
1306+ }
1307+
1308+ impl From < hir_def:: item_tree:: ItemTreeDataStats > for PrettyItemStats {
1309+ fn from ( value : hir_def:: item_tree:: ItemTreeDataStats ) -> Self {
1310+ Self {
1311+ traits : UsizeWithUnderscore ( value. traits ) ,
1312+ impls : UsizeWithUnderscore ( value. impls ) ,
1313+ mods : UsizeWithUnderscore ( value. mods ) ,
1314+ macro_calls : UsizeWithUnderscore ( value. macro_calls ) ,
1315+ macro_rules : UsizeWithUnderscore ( value. macro_rules ) ,
1316+ }
1317+ }
1318+ }
1319+
1320+ impl AddAssign for PrettyItemStats {
1321+ fn add_assign ( & mut self , rhs : Self ) {
1322+ self . traits += rhs. traits ;
1323+ self . impls += rhs. impls ;
1324+ self . mods += rhs. mods ;
1325+ self . macro_calls += rhs. macro_calls ;
1326+ self . macro_rules += rhs. macro_rules ;
1327+ }
1328+ }
1329+
1330+ impl fmt:: Display for PrettyItemStats {
1331+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1332+ write ! (
1333+ f,
1334+ "traits: {}, impl: {}, mods: {}, macro calls: {}, macro rules: {}" ,
1335+ self . traits, self . impls, self . mods, self . macro_calls, self . macro_rules
1336+ )
1337+ }
1338+ }
1339+
12781340// FIXME(salsa-transition): bring this back whenever we implement
12791341// Salsa's memory usage tracking to work with tracked functions.
12801342// fn syntax_len(node: SyntaxNode) -> usize {
0 commit comments