From b33b843f408fe73bde920c087de0622f46e853e5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 6 Mar 2020 17:23:08 +0100 Subject: Allow specifying additional info on call to profile --- crates/ra_hir_ty/src/db.rs | 11 +++++++- crates/ra_hir_ty/src/traits.rs | 5 +++- crates/ra_prof/src/lib.rs | 57 ++++++++++++++++++++++++++++-------------- 3 files changed, 52 insertions(+), 21 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs index c43619d1c..f79faa84d 100644 --- a/crates/ra_hir_ty/src/db.rs +++ b/crates/ra_hir_ty/src/db.rs @@ -16,6 +16,7 @@ use crate::{ Binders, CallableDef, GenericPredicate, InferenceResult, PolyFnSig, Substs, TraitRef, Ty, TyDefId, TypeCtor, ValueTyDefId, }; +use hir_expand::name::Name; #[salsa::query_group(HirDatabaseStorage)] #[salsa::requires(salsa::Database)] @@ -111,7 +112,15 @@ pub trait HirDatabase: DefDatabase { } fn infer(db: &impl HirDatabase, def: DefWithBodyId) -> Arc { - let _p = profile("wait_infer"); + let _p = profile("wait_infer").detail(|| match def { + DefWithBodyId::FunctionId(it) => db.function_data(it).name.to_string(), + DefWithBodyId::StaticId(it) => { + db.static_data(it).name.clone().unwrap_or_else(Name::missing).to_string() + } + DefWithBodyId::ConstId(it) => { + db.const_data(it).name.clone().unwrap_or_else(Name::missing).to_string() + } + }); db.do_infer(def) } diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index bc6ee2600..bdf23ac02 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs @@ -221,7 +221,10 @@ pub(crate) fn trait_solve_query( krate: CrateId, goal: Canonical>, ) -> Option { - let _p = profile("trait_solve_query"); + let _p = profile("trait_solve_query").detail(|| match &goal.value.value { + Obligation::Trait(it) => db.trait_data(it.trait_).name.to_string(), + Obligation::Projection(_) => "projection".to_string(), + }); log::debug!("trait_solve_query({})", goal.value.value.display(db)); if let Obligation::Projection(pred) = &goal.value.value { diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs index 6853a4794..9e167db96 100644 --- a/crates/ra_prof/src/lib.rs +++ b/crates/ra_prof/src/lib.rs @@ -88,7 +88,7 @@ pub type Label = &'static str; pub fn profile(label: Label) -> Profiler { assert!(!label.is_empty()); if !PROFILING_ENABLED.load(Ordering::Relaxed) { - return Profiler { label: None }; + return Profiler { label: None, detail: None }; } PROFILE_STACK.with(|stack| { @@ -101,15 +101,15 @@ pub fn profile(label: Label) -> Profiler { }; } if stack.starts.len() > stack.filter_data.depth { - return Profiler { label: None }; + return Profiler { label: None, detail: None }; } let allowed = &stack.filter_data.allowed; if stack.starts.is_empty() && !allowed.is_empty() && !allowed.contains(label) { - return Profiler { label: None }; + return Profiler { label: None, detail: None }; } stack.starts.push(Instant::now()); - Profiler { label: Some(label) } + Profiler { label: Some(label), detail: None } }) } @@ -130,6 +130,16 @@ pub fn print_time(label: Label) -> impl Drop { pub struct Profiler { label: Option