aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-06-30 12:40:01 +0100
committerAleksey Kladov <[email protected]>2019-06-30 12:49:45 +0100
commitd70520eb38c3f39823186c3b352efe4c910417f1 (patch)
tree74cde977e61652f9bd0af6c62449037ac100e94f /crates/ra_ide_api/src
parent2ad8220f58675193860337a00fed87162a98dc1a (diff)
print memory usage for queries
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/change.rs63
-rw-r--r--crates/ra_ide_api/src/lib.rs4
2 files changed, 66 insertions, 1 deletions
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs
index 8d9918d16..2dfedad01 100644
--- a/crates/ra_ide_api/src/change.rs
+++ b/crates/ra_ide_api/src/change.rs
@@ -9,7 +9,7 @@ use ra_db::{
9 salsa::{Database, SweepStrategy}, 9 salsa::{Database, SweepStrategy},
10}; 10};
11use ra_syntax::SourceFile; 11use ra_syntax::SourceFile;
12use ra_prof::profile; 12use ra_prof::{profile, Bytes, memory_usage};
13use relative_path::RelativePathBuf; 13use relative_path::RelativePathBuf;
14use rayon::prelude::*; 14use rayon::prelude::*;
15 15
@@ -243,4 +243,65 @@ impl RootDatabase {
243 self.query(hir::db::InferQuery).sweep(sweep); 243 self.query(hir::db::InferQuery).sweep(sweep);
244 self.query(hir::db::BodyHirQuery).sweep(sweep); 244 self.query(hir::db::BodyHirQuery).sweep(sweep);
245 } 245 }
246
247 pub(crate) fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> {
248 let mut acc: Vec<(String, Bytes)> = vec![];
249 let sweep = SweepStrategy::default().discard_values().sweep_all_revisions();
250 macro_rules! sweep_each_query {
251 ($($q:path)*) => {$(
252 let before = memory_usage().allocated;
253 self.query($q).sweep(sweep);
254 let after = memory_usage().allocated;
255 let q: $q = Default::default();
256 let name = format!("{:?}", q);
257 acc.push((name, before - after));
258 )*}
259 }
260 sweep_each_query![
261 ra_db::ParseQuery
262 ra_db::SourceRootCratesQuery
263 hir::db::AstIdMapQuery
264 hir::db::ParseMacroQuery
265 hir::db::MacroDefQuery
266 hir::db::MacroArgQuery
267 hir::db::MacroExpandQuery
268 hir::db::StructDataQuery
269 hir::db::EnumDataQuery
270 hir::db::TraitDataQuery
271 hir::db::TraitItemsIndexQuery
272 hir::db::RawItemsQuery
273 hir::db::RawItemsWithSourceMapQuery
274 hir::db::CrateDefMapQuery
275 hir::db::ImplsInModuleQuery
276 hir::db::ImplsInModuleWithSourceMapQuery
277 hir::db::GenericParamsQuery
278 hir::db::FnDataQuery
279 hir::db::TypeAliasDataQuery
280 hir::db::ConstDataQuery
281 hir::db::StaticDataQuery
282 hir::db::ModuleLangItemsQuery
283 hir::db::LangItemsQuery
284 hir::db::LangItemQuery
285 hir::db::DocumentationQuery
286 hir::db::ExprScopesQuery
287 hir::db::InferQuery
288 hir::db::TypeForDefQuery
289 hir::db::TypeForFieldQuery
290 hir::db::CallableItemSignatureQuery
291 hir::db::GenericPredicatesQuery
292 hir::db::GenericDefaultsQuery
293 hir::db::BodyWithSourceMapQuery
294 hir::db::BodyHirQuery
295 hir::db::ImplsInCrateQuery
296 hir::db::ImplsForTraitQuery
297 hir::db::AssociatedTyDataQuery
298 hir::db::TraitDatumQuery
299 hir::db::StructDatumQuery
300 hir::db::ImplDatumQuery
301 hir::db::ImplementsQuery
302 hir::db::NormalizeQuery
303 ];
304 acc.sort_by_key(|it| std::cmp::Reverse(it.1));
305 acc
306 }
246} 307}
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index 28a74c003..817e65df0 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -270,6 +270,10 @@ impl AnalysisHost {
270 pub fn collect_garbage(&mut self) { 270 pub fn collect_garbage(&mut self) {
271 self.db.collect_garbage(); 271 self.db.collect_garbage();
272 } 272 }
273 /// NB: this clears the database
274 pub fn per_query_memory_usage(&mut self) -> Vec<(String, ra_prof::Bytes)> {
275 self.db.per_query_memory_usage()
276 }
273 pub fn raw_database(&self) -> &(impl hir::db::HirDatabase + salsa::Database) { 277 pub fn raw_database(&self) -> &(impl hir::db::HirDatabase + salsa::Database) {
274 &self.db 278 &self.db
275 } 279 }