3
3
4
4
use std:: {
5
5
env, fmt,
6
+ ops:: AddAssign ,
6
7
time:: { SystemTime , UNIX_EPOCH } ,
7
8
} ;
8
9
@@ -129,6 +130,9 @@ impl flags::AnalysisStats {
129
130
let mut dep_item_trees = 0 ;
130
131
let mut workspace_item_trees = 0 ;
131
132
133
+ let mut workspace_item_stats = PrettyItemStats :: default ( ) ;
134
+ let mut dep_item_stats = PrettyItemStats :: default ( ) ;
135
+
132
136
for source_root_id in source_roots {
133
137
let source_root = db. source_root ( source_root_id) . source_root ( db) ;
134
138
for file_id in source_root. iter ( ) {
@@ -137,16 +141,24 @@ impl flags::AnalysisStats {
137
141
// measure workspace/project code
138
142
if !source_root. is_library || self . with_deps {
139
143
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 ( ) ;
141
148
142
149
workspace_loc += length;
143
150
workspace_item_trees += 1 ;
151
+ workspace_item_stats += item_stats;
144
152
} else {
145
153
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 ( ) ;
147
158
148
159
dep_loc += length;
149
- dep_item_trees += 1
160
+ dep_item_trees += 1 ;
161
+ dep_item_stats += item_stats;
150
162
}
151
163
}
152
164
}
@@ -161,11 +173,13 @@ impl flags::AnalysisStats {
161
173
UsizeWithUnderscore ( dep_loc) ,
162
174
UsizeWithUnderscore ( dep_item_trees) ,
163
175
) ;
176
+ eprintln ! ( " dependency item stats: {}" , dep_item_stats) ;
164
177
eprintln ! (
165
178
" workspace lines of code: {}, item trees: {}" ,
166
179
UsizeWithUnderscore ( workspace_loc) ,
167
180
UsizeWithUnderscore ( workspace_item_trees) ,
168
181
) ;
182
+ eprintln ! ( " workspace stats: {}" , workspace_item_stats) ;
169
183
170
184
// FIXME(salsa-transition): bring back stats for ParseQuery (file size)
171
185
// and ParseMacroExpansionQuery (macro expansion "file") size whenever we implement
@@ -1258,6 +1272,7 @@ fn percentage(n: u64, total: u64) -> u64 {
1258
1272
( n * 100 ) . checked_div ( total) . unwrap_or ( 100 )
1259
1273
}
1260
1274
1275
+ #[ derive( Default , Debug , Eq , PartialEq ) ]
1261
1276
struct UsizeWithUnderscore ( usize ) ;
1262
1277
1263
1278
impl fmt:: Display for UsizeWithUnderscore {
@@ -1282,6 +1297,53 @@ impl fmt::Display for UsizeWithUnderscore {
1282
1297
}
1283
1298
}
1284
1299
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
+
1285
1347
// FIXME(salsa-transition): bring this back whenever we implement
1286
1348
// Salsa's memory usage tracking to work with tracked functions.
1287
1349
// fn syntax_len(node: SyntaxNode) -> usize {
0 commit comments