33
44use std:: {
55 env, fmt,
6+ ops:: AddAssign ,
67 time:: { SystemTime , UNIX_EPOCH } ,
78} ;
89
@@ -129,6 +130,9 @@ impl flags::AnalysisStats {
129130 let mut dep_item_trees = 0 ;
130131 let mut workspace_item_trees = 0 ;
131132
133+ let mut workspace_item_stats = PrettyItemStats :: default ( ) ;
134+ let mut dep_item_stats = PrettyItemStats :: default ( ) ;
135+
132136 for source_root_id in source_roots {
133137 let source_root = db. source_root ( source_root_id) . source_root ( db) ;
134138 for file_id in source_root. iter ( ) {
@@ -137,16 +141,24 @@ impl flags::AnalysisStats {
137141 // measure workspace/project code
138142 if !source_root. is_library || self . with_deps {
139143 let length = db. file_text ( file_id) . text ( db) . lines ( ) . count ( ) ;
140- db. file_item_tree ( EditionedFileId :: current_edition ( file_id) . into ( ) ) ;
144+ let item_stats = db
145+ . file_item_tree ( EditionedFileId :: current_edition ( file_id) . into ( ) )
146+ . item_tree_stats ( )
147+ . into ( ) ;
141148
142149 workspace_loc += length;
143150 workspace_item_trees += 1 ;
151+ workspace_item_stats += item_stats;
144152 } else {
145153 let length = db. file_text ( file_id) . text ( db) . lines ( ) . count ( ) ;
146- db. file_item_tree ( EditionedFileId :: current_edition ( file_id) . into ( ) ) ;
154+ let item_stats = db
155+ . file_item_tree ( EditionedFileId :: current_edition ( file_id) . into ( ) )
156+ . item_tree_stats ( )
157+ . into ( ) ;
147158
148159 dep_loc += length;
149- dep_item_trees += 1
160+ dep_item_trees += 1 ;
161+ dep_item_stats += item_stats;
150162 }
151163 }
152164 }
@@ -161,11 +173,13 @@ impl flags::AnalysisStats {
161173 UsizeWithUnderscore ( dep_loc) ,
162174 UsizeWithUnderscore ( dep_item_trees) ,
163175 ) ;
176+ eprintln ! ( " dependency item stats: {}" , dep_item_stats) ;
164177 eprintln ! (
165178 " workspace lines of code: {}, item trees: {}" ,
166179 UsizeWithUnderscore ( workspace_loc) ,
167180 UsizeWithUnderscore ( workspace_item_trees) ,
168181 ) ;
182+ eprintln ! ( " workspace stats: {}" , workspace_item_stats) ;
169183
170184 // FIXME(salsa-transition): bring back stats for ParseQuery (file size)
171185 // and ParseMacroExpansionQuery (macro expansion "file") size whenever we implement
@@ -1258,6 +1272,7 @@ fn percentage(n: u64, total: u64) -> u64 {
12581272 ( n * 100 ) . checked_div ( total) . unwrap_or ( 100 )
12591273}
12601274
1275+ #[ derive( Default , Debug , Eq , PartialEq ) ]
12611276struct UsizeWithUnderscore ( usize ) ;
12621277
12631278impl fmt:: Display for UsizeWithUnderscore {
@@ -1282,6 +1297,53 @@ impl fmt::Display for UsizeWithUnderscore {
12821297 }
12831298}
12841299
1300+ impl std:: ops:: AddAssign for UsizeWithUnderscore {
1301+ fn add_assign ( & mut self , other : UsizeWithUnderscore ) {
1302+ self . 0 += other. 0 ;
1303+ }
1304+ }
1305+
1306+ #[ derive( Default , Debug , Eq , PartialEq ) ]
1307+ struct PrettyItemStats {
1308+ traits : UsizeWithUnderscore ,
1309+ impls : UsizeWithUnderscore ,
1310+ mods : UsizeWithUnderscore ,
1311+ macro_calls : UsizeWithUnderscore ,
1312+ macro_rules : UsizeWithUnderscore ,
1313+ }
1314+
1315+ impl From < hir_def:: item_tree:: ItemTreeDataStats > for PrettyItemStats {
1316+ fn from ( value : hir_def:: item_tree:: ItemTreeDataStats ) -> Self {
1317+ Self {
1318+ traits : UsizeWithUnderscore ( value. traits ) ,
1319+ impls : UsizeWithUnderscore ( value. impls ) ,
1320+ mods : UsizeWithUnderscore ( value. mods ) ,
1321+ macro_calls : UsizeWithUnderscore ( value. macro_calls ) ,
1322+ macro_rules : UsizeWithUnderscore ( value. macro_rules ) ,
1323+ }
1324+ }
1325+ }
1326+
1327+ impl AddAssign for PrettyItemStats {
1328+ fn add_assign ( & mut self , rhs : Self ) {
1329+ self . traits += rhs. traits ;
1330+ self . impls += rhs. impls ;
1331+ self . mods += rhs. mods ;
1332+ self . macro_calls += rhs. macro_calls ;
1333+ self . macro_rules += rhs. macro_rules ;
1334+ }
1335+ }
1336+
1337+ impl fmt:: Display for PrettyItemStats {
1338+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1339+ write ! (
1340+ f,
1341+ "traits: {}, impl: {}, mods: {}, macro calls: {}, macro rules: {}" ,
1342+ self . traits, self . impls, self . mods, self . macro_calls, self . macro_rules
1343+ )
1344+ }
1345+ }
1346+
12851347// FIXME(salsa-transition): bring this back whenever we implement
12861348// Salsa's memory usage tracking to work with tracked functions.
12871349// fn syntax_len(node: SyntaxNode) -> usize {
0 commit comments