From d70520eb38c3f39823186c3b352efe4c910417f1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 30 Jun 2019 14:40:01 +0300 Subject: print memory usage for queries --- crates/ra_ide_api/src/change.rs | 63 ++++++++++++++++++++++++++++++++++++++++- crates/ra_ide_api/src/lib.rs | 4 +++ 2 files changed, 66 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide_api/src') 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::{ salsa::{Database, SweepStrategy}, }; use ra_syntax::SourceFile; -use ra_prof::profile; +use ra_prof::{profile, Bytes, memory_usage}; use relative_path::RelativePathBuf; use rayon::prelude::*; @@ -243,4 +243,65 @@ impl RootDatabase { self.query(hir::db::InferQuery).sweep(sweep); self.query(hir::db::BodyHirQuery).sweep(sweep); } + + pub(crate) fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> { + let mut acc: Vec<(String, Bytes)> = vec![]; + let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); + macro_rules! sweep_each_query { + ($($q:path)*) => {$( + let before = memory_usage().allocated; + self.query($q).sweep(sweep); + let after = memory_usage().allocated; + let q: $q = Default::default(); + let name = format!("{:?}", q); + acc.push((name, before - after)); + )*} + } + sweep_each_query![ + ra_db::ParseQuery + ra_db::SourceRootCratesQuery + hir::db::AstIdMapQuery + hir::db::ParseMacroQuery + hir::db::MacroDefQuery + hir::db::MacroArgQuery + hir::db::MacroExpandQuery + hir::db::StructDataQuery + hir::db::EnumDataQuery + hir::db::TraitDataQuery + hir::db::TraitItemsIndexQuery + hir::db::RawItemsQuery + hir::db::RawItemsWithSourceMapQuery + hir::db::CrateDefMapQuery + hir::db::ImplsInModuleQuery + hir::db::ImplsInModuleWithSourceMapQuery + hir::db::GenericParamsQuery + hir::db::FnDataQuery + hir::db::TypeAliasDataQuery + hir::db::ConstDataQuery + hir::db::StaticDataQuery + hir::db::ModuleLangItemsQuery + hir::db::LangItemsQuery + hir::db::LangItemQuery + hir::db::DocumentationQuery + hir::db::ExprScopesQuery + hir::db::InferQuery + hir::db::TypeForDefQuery + hir::db::TypeForFieldQuery + hir::db::CallableItemSignatureQuery + hir::db::GenericPredicatesQuery + hir::db::GenericDefaultsQuery + hir::db::BodyWithSourceMapQuery + hir::db::BodyHirQuery + hir::db::ImplsInCrateQuery + hir::db::ImplsForTraitQuery + hir::db::AssociatedTyDataQuery + hir::db::TraitDatumQuery + hir::db::StructDatumQuery + hir::db::ImplDatumQuery + hir::db::ImplementsQuery + hir::db::NormalizeQuery + ]; + acc.sort_by_key(|it| std::cmp::Reverse(it.1)); + acc + } } 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 { pub fn collect_garbage(&mut self) { self.db.collect_garbage(); } + /// NB: this clears the database + pub fn per_query_memory_usage(&mut self) -> Vec<(String, ra_prof::Bytes)> { + self.db.per_query_memory_usage() + } pub fn raw_database(&self) -> &(impl hir::db::HirDatabase + salsa::Database) { &self.db } -- cgit v1.2.3