@@ -118,27 +118,67 @@ impl flags::AnalysisStats {
118
118
}
119
119
120
120
let mut item_tree_sw = self . stop_watch ( ) ;
121
- let mut num_item_trees = 0 ;
122
121
let source_roots = krates
123
122
. iter ( )
124
123
. cloned ( )
125
124
. map ( |krate| db. file_source_root ( krate. root_file ( db) ) . source_root_id ( db) )
126
125
. unique ( ) ;
126
+
127
+ let mut dep_loc = 0 ;
128
+ let mut workspace_loc = 0 ;
129
+ let mut deps_item_trees = 0 ;
130
+ let mut workspace_item_trees = 0 ;
131
+
127
132
for source_root_id in source_roots {
128
133
let source_root = db. source_root ( source_root_id) . source_root ( db) ;
129
- if !source_root. is_library || self . with_deps {
130
- for file_id in source_root. iter ( ) {
131
- if let Some ( p) = source_root. path_for_file ( & file_id) {
132
- if let Some ( ( _, Some ( "rs" ) ) ) = p. name_and_extension ( ) {
134
+ for file_id in source_root. iter ( ) {
135
+ if let Some ( p) = source_root. path_for_file ( & file_id) {
136
+ if let Some ( ( _, Some ( "rs" ) ) ) = p. name_and_extension ( ) {
137
+ // measure workspace/project code
138
+ if !source_root. is_library || self . with_deps {
139
+ let length = db. file_text ( file_id) . text ( db) . lines ( ) . count ( ) ;
133
140
db. file_item_tree ( EditionedFileId :: current_edition ( file_id) . into ( ) ) ;
134
- num_item_trees += 1 ;
141
+
142
+ workspace_loc += length;
143
+ workspace_item_trees += 1 ;
144
+ } else if self . source_stats {
145
+ let length = db. file_text ( file_id) . text ( db) . lines ( ) . count ( ) ;
146
+ db. file_item_tree ( EditionedFileId :: current_edition ( file_id) . into ( ) ) ;
147
+
148
+ dep_loc += length;
149
+ deps_item_trees += 1
135
150
}
136
151
}
137
152
}
138
153
}
139
154
}
140
- eprintln ! ( " item trees: {num_item_trees }" ) ;
155
+ eprintln ! ( " item trees: {workspace_item_trees }" ) ;
141
156
let item_tree_time = item_tree_sw. elapsed ( ) ;
157
+
158
+ if self . source_stats {
159
+ eprintln ! ( "Source stats:" ) ;
160
+ eprintln ! ( " dependency lines of code: {dep_loc}, item trees: {deps_item_trees}" ) ;
161
+ eprintln ! (
162
+ " workspace lines of code: {workspace_loc}, item trees: {workspace_item_trees}"
163
+ ) ;
164
+
165
+ // FIXME(salsa-transition): bring back stats for ParseQuery (file size)
166
+ // and ParseMacroExpansionQuery (mcaro expansion "file") size whenever we implement
167
+ // Salsa's memory usage tracking works with tracked functions.
168
+
169
+ // let mut total_file_size = Bytes::default();
170
+ // for e in ide_db::base_db::ParseQuery.in_db(db).entries::<Vec<_>>() {
171
+ // total_file_size += syntax_len(db.parse(e.key).syntax_node())
172
+ // }
173
+
174
+ // let mut total_macro_file_size = Bytes::default();
175
+ // for e in hir::db::ParseMacroExpansionQuery.in_db(db).entries::<Vec<_>>() {
176
+ // let val = db.parse_macro_expansion(e.key).value.0;
177
+ // total_macro_file_size += syntax_len(val.syntax_node())
178
+ // }
179
+ // eprintln!("source files: {total_file_size}, macro files: {total_macro_file_size}");
180
+ }
181
+
142
182
eprintln ! ( "{:<20} {}" , "Item Tree Collection:" , item_tree_time) ;
143
183
report_metric ( "item tree time" , item_tree_time. time . as_millis ( ) as u64 , "ms" ) ;
144
184
@@ -168,6 +208,11 @@ impl flags::AnalysisStats {
168
208
let mut bodies = Vec :: new ( ) ;
169
209
let mut adts = Vec :: new ( ) ;
170
210
let mut file_ids = Vec :: new ( ) ;
211
+
212
+ let mut num_traits = 0 ;
213
+ let mut num_macro_rules_macros = 0 ;
214
+ let mut num_proc_macros = 0 ;
215
+
171
216
while let Some ( module) = visit_queue. pop ( ) {
172
217
if visited_modules. insert ( module) {
173
218
file_ids. extend ( module. as_source_file_id ( db) ) ;
@@ -189,6 +234,14 @@ impl flags::AnalysisStats {
189
234
bodies. push ( DefWithBody :: from ( c) ) ;
190
235
}
191
236
ModuleDef :: Static ( s) => bodies. push ( DefWithBody :: from ( s) ) ,
237
+ ModuleDef :: Trait ( _) => num_traits += 1 ,
238
+ ModuleDef :: Macro ( m) => match m. kind ( db) {
239
+ hir:: MacroKind :: Declarative => num_macro_rules_macros += 1 ,
240
+ hir:: MacroKind :: Derive
241
+ | hir:: MacroKind :: Attr
242
+ | hir:: MacroKind :: ProcMacro => num_proc_macros += 1 ,
243
+ _ => ( ) ,
244
+ } ,
192
245
_ => ( ) ,
193
246
} ;
194
247
}
@@ -217,6 +270,8 @@ impl flags::AnalysisStats {
217
270
. filter( |it| matches!( it, DefWithBody :: Const ( _) | DefWithBody :: Static ( _) ) )
218
271
. count( ) ,
219
272
) ;
273
+ eprintln ! ( " traits: {num_traits}, macro_rules macros: {num_macro_rules_macros}, proc_macros: {num_proc_macros}" ) ;
274
+
220
275
let crate_def_map_time = crate_def_map_sw. elapsed ( ) ;
221
276
eprintln ! ( "{:<20} {}" , "Item Collection:" , crate_def_map_time) ;
222
277
report_metric ( "crate def map time" , crate_def_map_time. time . as_millis ( ) as u64 , "ms" ) ;
@@ -264,24 +319,6 @@ impl flags::AnalysisStats {
264
319
}
265
320
report_metric ( "total memory" , total_span. memory . allocated . megabytes ( ) as u64 , "MB" ) ;
266
321
267
- if self . source_stats {
268
- // FIXME(salsa-transition): bring back stats for ParseQuery (file size)
269
- // and ParseMacroExpansionQuery (mcaro expansion "file") size whenever we implement
270
- // Salsa's memory usage tracking works with tracked functions.
271
-
272
- // let mut total_file_size = Bytes::default();
273
- // for e in ide_db::base_db::ParseQuery.in_db(db).entries::<Vec<_>>() {
274
- // total_file_size += syntax_len(db.parse(e.key).syntax_node())
275
- // }
276
-
277
- // let mut total_macro_file_size = Bytes::default();
278
- // for e in hir::db::ParseMacroExpansionQuery.in_db(db).entries::<Vec<_>>() {
279
- // let val = db.parse_macro_expansion(e.key).value.0;
280
- // total_macro_file_size += syntax_len(val.syntax_node())
281
- // }
282
- // eprintln!("source files: {total_file_size}, macro files: {total_macro_file_size}");
283
- }
284
-
285
322
if verbosity. is_verbose ( ) {
286
323
print_memory_usage ( host, vfs) ;
287
324
}
0 commit comments