3
3
4
4
use std:: {
5
5
env, fmt,
6
+ ops:: AddAssign ,
6
7
time:: { SystemTime , UNIX_EPOCH } ,
7
8
} ;
8
9
@@ -125,6 +126,9 @@ impl flags::AnalysisStats {
125
126
let mut dep_item_trees = 0 ;
126
127
let mut workspace_item_trees = 0 ;
127
128
129
+ let mut workspace_item_stats = PrettyItemStats :: default ( ) ;
130
+ let mut dep_item_stats = PrettyItemStats :: default ( ) ;
131
+
128
132
for source_root_id in source_roots {
129
133
let source_root = db. source_root ( source_root_id) . source_root ( db) ;
130
134
for file_id in source_root. iter ( ) {
@@ -133,16 +137,24 @@ impl flags::AnalysisStats {
133
137
// measure workspace/project code
134
138
if !source_root. is_library || self . with_deps {
135
139
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 ( ) ;
137
144
138
145
workspace_loc += length;
139
146
workspace_item_trees += 1 ;
147
+ workspace_item_stats += item_stats;
140
148
} else {
141
149
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 ( ) ;
143
154
144
155
dep_loc += length;
145
- dep_item_trees += 1
156
+ dep_item_trees += 1 ;
157
+ dep_item_stats += item_stats;
146
158
}
147
159
}
148
160
}
@@ -157,11 +169,13 @@ impl flags::AnalysisStats {
157
169
UsizeWithUnderscore ( dep_loc) ,
158
170
UsizeWithUnderscore ( dep_item_trees) ,
159
171
) ;
172
+ eprintln ! ( " dependency item stats: {}" , dep_item_stats) ;
160
173
eprintln ! (
161
174
" workspace lines of code: {}, item trees: {}" ,
162
175
UsizeWithUnderscore ( workspace_loc) ,
163
176
UsizeWithUnderscore ( workspace_item_trees) ,
164
177
) ;
178
+ eprintln ! ( " workspace stats: {}" , workspace_item_stats) ;
165
179
166
180
// FIXME(salsa-transition): bring back stats for ParseQuery (file size)
167
181
// and ParseMacroExpansionQuery (macro expansion "file") size whenever we implement
@@ -1251,6 +1265,7 @@ fn percentage(n: u64, total: u64) -> u64 {
1251
1265
( n * 100 ) . checked_div ( total) . unwrap_or ( 100 )
1252
1266
}
1253
1267
1268
+ #[ derive( Default , Debug , Eq , PartialEq ) ]
1254
1269
struct UsizeWithUnderscore ( usize ) ;
1255
1270
1256
1271
impl fmt:: Display for UsizeWithUnderscore {
@@ -1275,6 +1290,53 @@ impl fmt::Display for UsizeWithUnderscore {
1275
1290
}
1276
1291
}
1277
1292
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
+
1278
1340
// FIXME(salsa-transition): bring this back whenever we implement
1279
1341
// Salsa's memory usage tracking to work with tracked functions.
1280
1342
// fn syntax_len(node: SyntaxNode) -> usize {
0 commit comments