From c981ff09442cf04cf469223d7690a365126f45ea Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Fri, 26 Apr 2024 17:00:58 -0700 Subject: [PATCH] fix: Tracing span names should match function names When viewing traces, it's slightly confusing when the span name doesn't match the function name. Ensure the names are consistent. (It might be worth moving most of these to use #[tracing::instrument] so the name can never go stale. @davidbarsky suggested that is marginally slower, so I've just done the simple change here.) --- crates/base-db/src/change.rs | 2 +- crates/base-db/src/lib.rs | 2 +- crates/hir-ty/src/chalk_db.rs | 2 +- crates/hir-ty/src/method_resolution.rs | 2 +- crates/hir/src/lib.rs | 3 ++- crates/hir/src/semantics.rs | 4 ++-- crates/hir/src/semantics/source_to_def.rs | 2 +- .../ide-completion/src/completions/flyimport.rs | 2 +- crates/ide-completion/src/render.rs | 6 +++--- crates/ide-completion/src/render/literal.rs | 2 +- crates/ide-completion/src/render/macro_.rs | 2 +- crates/ide-db/src/imports/import_assets.rs | 16 +++++++--------- crates/ide-db/src/imports/insert_use.rs | 2 +- crates/ide-db/src/prime_caches.rs | 2 +- crates/ide/src/inlay_hints.rs | 2 +- crates/load-cargo/src/lib.rs | 3 ++- crates/proc-macro-api/src/lib.rs | 2 +- crates/rust-analyzer/src/cli/parse.rs | 2 +- .../rust-analyzer/src/handlers/notification.rs | 2 +- crates/rust-analyzer/src/handlers/request.rs | 2 +- 20 files changed, 31 insertions(+), 31 deletions(-) diff --git a/crates/base-db/src/change.rs b/crates/base-db/src/change.rs index f202a885e2..927b2108a6 100644 --- a/crates/base-db/src/change.rs +++ b/crates/base-db/src/change.rs @@ -51,7 +51,7 @@ impl FileChange { } pub fn apply(self, db: &mut dyn SourceDatabaseExt) { - let _p = tracing::span!(tracing::Level::INFO, "RootDatabase::apply_change").entered(); + let _p = tracing::span!(tracing::Level::INFO, "FileChange::apply").entered(); if let Some(roots) = self.roots { for (idx, root) in roots.into_iter().enumerate() { let root_id = SourceRootId(idx as u32); diff --git a/crates/base-db/src/lib.rs b/crates/base-db/src/lib.rs index 82aff6e3b8..f8cb431c3c 100644 --- a/crates/base-db/src/lib.rs +++ b/crates/base-db/src/lib.rs @@ -82,7 +82,7 @@ fn toolchain_channel(db: &dyn SourceDatabase, krate: CrateId) -> Option Parse { - let _p = tracing::span!(tracing::Level::INFO, "parse_query", ?file_id).entered(); + let _p = tracing::span!(tracing::Level::INFO, "parse", ?file_id).entered(); let text = db.file_text(file_id); // FIXME: Edition based parsing SourceFile::parse(&text, span::Edition::CURRENT) diff --git a/crates/hir-ty/src/chalk_db.rs b/crates/hir-ty/src/chalk_db.rs index 46612242b0..84ac8740ec 100644 --- a/crates/hir-ty/src/chalk_db.rs +++ b/crates/hir-ty/src/chalk_db.rs @@ -806,7 +806,7 @@ pub(crate) fn impl_datum_query( krate: CrateId, impl_id: ImplId, ) -> Arc { - let _p = tracing::span!(tracing::Level::INFO, "impl_datum").entered(); + let _p = tracing::span!(tracing::Level::INFO, "impl_datum_query").entered(); debug!("impl_datum {:?}", impl_id); let impl_: hir_def::ImplId = from_chalk(db, impl_id); impl_def_datum(db, krate, impl_id, impl_) diff --git a/crates/hir-ty/src/method_resolution.rs b/crates/hir-ty/src/method_resolution.rs index cd72349471..cb56a6f0bf 100644 --- a/crates/hir-ty/src/method_resolution.rs +++ b/crates/hir-ty/src/method_resolution.rs @@ -368,7 +368,7 @@ pub(crate) fn incoherent_inherent_impl_crates( krate: CrateId, fp: TyFingerprint, ) -> SmallVec<[CrateId; 2]> { - let _p = tracing::span!(tracing::Level::INFO, "inherent_impl_crates_query").entered(); + let _p = tracing::span!(tracing::Level::INFO, "incoherent_inherent_impl_crates").entered(); let mut res = SmallVec::new(); let crate_graph = db.crate_graph(); diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 0b525d61ce..149e75c45c 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -4503,7 +4503,8 @@ impl Type { name: Option<&Name>, mut callback: impl FnMut(Function) -> Option, ) -> Option { - let _p = tracing::span!(tracing::Level::INFO, "iterate_method_candidates").entered(); + let _p = + tracing::span!(tracing::Level::INFO, "iterate_method_candidates_with_traits").entered(); let mut slot = None; self.iterate_method_candidates_dyn( diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index b99cde6db4..6c70cc4baf 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -723,7 +723,7 @@ impl<'db> SemanticsImpl<'db> { mut token: SyntaxToken, f: &mut dyn FnMut(InFile) -> ControlFlow<()>, ) { - let _p = tracing::span!(tracing::Level::INFO, "descend_into_macros").entered(); + let _p = tracing::span!(tracing::Level::INFO, "descend_into_macros_impl").entered(); let (sa, span, file_id) = match token.parent().and_then(|parent| self.analyze_no_infer(&parent)) { Some(sa) => match sa.file_id.file_id() { @@ -1372,7 +1372,7 @@ impl<'db> SemanticsImpl<'db> { offset: Option, infer_body: bool, ) -> Option { - let _p = tracing::span!(tracing::Level::INFO, "Semantics::analyze_impl").entered(); + let _p = tracing::span!(tracing::Level::INFO, "SemanticsImpl::analyze_impl").entered(); let node = self.find_file(node); let container = self.with_ctx(|ctx| ctx.find_container(node))?; diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index 007709a836..d2bd8b0e79 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs @@ -118,7 +118,7 @@ pub(super) struct SourceToDefCtx<'a, 'b> { impl SourceToDefCtx<'_, '_> { pub(super) fn file_to_def(&self, file: FileId) -> SmallVec<[ModuleId; 1]> { - let _p = tracing::span!(tracing::Level::INFO, "SourceBinder::file_to_module_def").entered(); + let _p = tracing::span!(tracing::Level::INFO, "SourceToDefCtx::file_to_def").entered(); let mut mods = SmallVec::new(); for &crate_id in self.db.relevant_crates(file).iter() { // Note: `mod` declarations in block modules cannot be supported here diff --git a/crates/ide-completion/src/completions/flyimport.rs b/crates/ide-completion/src/completions/flyimport.rs index 3bc329ecd7..bf6747d71b 100644 --- a/crates/ide-completion/src/completions/flyimport.rs +++ b/crates/ide-completion/src/completions/flyimport.rs @@ -296,7 +296,7 @@ fn import_on_the_fly_pat_( position: SyntaxNode, potential_import_name: String, ) -> Option<()> { - let _p = tracing::span!(tracing::Level::INFO, "import_on_the_fly_pat", ?potential_import_name) + let _p = tracing::span!(tracing::Level::INFO, "import_on_the_fly_pat_", ?potential_import_name) .entered(); ImportScope::find_insert_use_container(&position, &ctx.sema)?; diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs index ca0424809e..0f13bea7b6 100644 --- a/crates/ide-completion/src/render.rs +++ b/crates/ide-completion/src/render.rs @@ -368,7 +368,7 @@ fn render_resolution_pat( import_to_add: Option, resolution: ScopeDef, ) -> Builder { - let _p = tracing::span!(tracing::Level::INFO, "render_resolution").entered(); + let _p = tracing::span!(tracing::Level::INFO, "render_resolution_pat").entered(); use hir::ModuleDef::*; if let ScopeDef::ModuleDef(Macro(mac)) = resolution { @@ -386,7 +386,7 @@ fn render_resolution_path( import_to_add: Option, resolution: ScopeDef, ) -> Builder { - let _p = tracing::span!(tracing::Level::INFO, "render_resolution").entered(); + let _p = tracing::span!(tracing::Level::INFO, "render_resolution_path").entered(); use hir::ModuleDef::*; match resolution { @@ -494,7 +494,7 @@ fn render_resolution_simple_( import_to_add: Option, resolution: ScopeDef, ) -> Builder { - let _p = tracing::span!(tracing::Level::INFO, "render_resolution").entered(); + let _p = tracing::span!(tracing::Level::INFO, "render_resolution_simple_").entered(); let db = ctx.db(); let ctx = ctx.import_to_add(import_to_add); diff --git a/crates/ide-completion/src/render/literal.rs b/crates/ide-completion/src/render/literal.rs index f52a5f7625..9c5cb1e37d 100644 --- a/crates/ide-completion/src/render/literal.rs +++ b/crates/ide-completion/src/render/literal.rs @@ -27,7 +27,7 @@ pub(crate) fn render_variant_lit( variant: hir::Variant, path: Option, ) -> Option { - let _p = tracing::span!(tracing::Level::INFO, "render_enum_variant").entered(); + let _p = tracing::span!(tracing::Level::INFO, "render_variant_lit").entered(); let db = ctx.db(); let name = local_name.unwrap_or_else(|| variant.name(db)); diff --git a/crates/ide-completion/src/render/macro_.rs b/crates/ide-completion/src/render/macro_.rs index 540cfd03d6..8b81a95abb 100644 --- a/crates/ide-completion/src/render/macro_.rs +++ b/crates/ide-completion/src/render/macro_.rs @@ -27,7 +27,7 @@ pub(crate) fn render_macro_pat( name: hir::Name, macro_: hir::Macro, ) -> Builder { - let _p = tracing::span!(tracing::Level::INFO, "render_macro").entered(); + let _p = tracing::span!(tracing::Level::INFO, "render_macro_pat").entered(); render(ctx, false, false, false, name, macro_) } diff --git a/crates/ide-db/src/imports/import_assets.rs b/crates/ide-db/src/imports/import_assets.rs index c597555a3b..766bfcf4d0 100644 --- a/crates/ide-db/src/imports/import_assets.rs +++ b/crates/ide-db/src/imports/import_assets.rs @@ -209,8 +209,7 @@ impl ImportAssets { prefer_no_std: bool, prefer_prelude: bool, ) -> impl Iterator { - let _p = - tracing::span!(tracing::Level::INFO, "import_assets::search_for_imports").entered(); + let _p = tracing::span!(tracing::Level::INFO, "ImportAssets::search_for_imports").entered(); self.search_for(sema, Some(prefix_kind), prefer_no_std, prefer_prelude) } @@ -221,7 +220,7 @@ impl ImportAssets { prefer_no_std: bool, prefer_prelude: bool, ) -> impl Iterator { - let _p = tracing::span!(tracing::Level::INFO, "import_assets::search_for_relative_paths") + let _p = tracing::span!(tracing::Level::INFO, "ImportAssets::search_for_relative_paths") .entered(); self.search_for(sema, None, prefer_no_std, prefer_prelude) } @@ -263,7 +262,7 @@ impl ImportAssets { prefer_no_std: bool, prefer_prelude: bool, ) -> impl Iterator { - let _p = tracing::span!(tracing::Level::INFO, "import_assets::search_for").entered(); + let _p = tracing::span!(tracing::Level::INFO, "ImportAssets::search_for").entered(); let scope = match sema.scope(&self.candidate_node) { Some(it) => it, @@ -308,7 +307,7 @@ impl ImportAssets { } fn scope_definitions(&self, sema: &Semantics<'_, RootDatabase>) -> FxHashSet { - let _p = tracing::span!(tracing::Level::INFO, "import_assets::scope_definitions").entered(); + let _p = tracing::span!(tracing::Level::INFO, "ImportAssets::scope_definitions").entered(); let mut scope_definitions = FxHashSet::default(); if let Some(scope) = sema.scope(&self.candidate_node) { scope.process_all_names(&mut |_, scope_def| { @@ -327,7 +326,7 @@ fn path_applicable_imports( scope_filter: impl Fn(ItemInNs) -> bool + Copy, ) -> FxHashSet { let _p = - tracing::span!(tracing::Level::INFO, "import_assets::path_applicable_imports").entered(); + tracing::span!(tracing::Level::INFO, "ImportAssets::path_applicable_imports").entered(); match &path_candidate.qualifier { None => { @@ -374,7 +373,7 @@ fn import_for_item( original_item: ItemInNs, scope_filter: impl Fn(ItemInNs) -> bool, ) -> Option { - let _p = tracing::span!(tracing::Level::INFO, "import_assets::import_for_item").entered(); + let _p = tracing::span!(tracing::Level::INFO, "ImportAssets::import_for_item").entered(); let [first_segment, ..] = unresolved_qualifier else { return None }; let item_as_assoc = item_as_assoc(db, original_item); @@ -508,8 +507,7 @@ fn trait_applicable_items( mod_path: impl Fn(ItemInNs) -> Option, scope_filter: impl Fn(hir::Trait) -> bool, ) -> FxHashSet { - let _p = - tracing::span!(tracing::Level::INFO, "import_assets::trait_applicable_items").entered(); + let _p = tracing::span!(tracing::Level::INFO, "ImportAssets::trait_applicable_items").entered(); let db = sema.db; diff --git a/crates/ide-db/src/imports/insert_use.rs b/crates/ide-db/src/imports/insert_use.rs index e97f1b8614..026d4e36f9 100644 --- a/crates/ide-db/src/imports/insert_use.rs +++ b/crates/ide-db/src/imports/insert_use.rs @@ -194,7 +194,7 @@ fn insert_use_with_alias_option( cfg: &InsertUseConfig, alias: Option, ) { - let _p = tracing::span!(tracing::Level::INFO, "insert_use").entered(); + let _p = tracing::span!(tracing::Level::INFO, "insert_use_with_alias_option").entered(); let mut mb = match cfg.granularity { ImportGranularity::Crate => Some(MergeBehavior::Crate), ImportGranularity::Module => Some(MergeBehavior::Module), diff --git a/crates/ide-db/src/prime_caches.rs b/crates/ide-db/src/prime_caches.rs index 0db87c6bc4..58077f636b 100644 --- a/crates/ide-db/src/prime_caches.rs +++ b/crates/ide-db/src/prime_caches.rs @@ -32,7 +32,7 @@ pub fn parallel_prime_caches( num_worker_threads: u8, cb: &(dyn Fn(ParallelPrimeCachesProgress) + Sync), ) { - let _p = tracing::span!(tracing::Level::INFO, "prime_caches").entered(); + let _p = tracing::span!(tracing::Level::INFO, "parallel_prime_caches").entered(); let graph = db.crate_graph(); let mut crates_to_prime = { diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 15eecd1b54..dda5a005a7 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -496,7 +496,7 @@ pub(crate) fn inlay_hints_resolve( config: &InlayHintsConfig, hasher: impl Fn(&InlayHint) -> u64, ) -> Option { - let _p = tracing::span!(tracing::Level::INFO, "inlay_hints").entered(); + let _p = tracing::span!(tracing::Level::INFO, "inlay_hints_resolve").entered(); let sema = Semantics::new(db); let file = sema.parse(file_id); let file = file.syntax(); diff --git a/crates/load-cargo/src/lib.rs b/crates/load-cargo/src/lib.rs index c859941abd..dc8ea51039 100644 --- a/crates/load-cargo/src/lib.rs +++ b/crates/load-cargo/src/lib.rs @@ -352,7 +352,8 @@ fn load_crate_graph( } } vfs::loader::Message::Loaded { files } | vfs::loader::Message::Changed { files } => { - let _p = tracing::span!(Level::INFO, "LoadCargo::load_file_contents").entered(); + let _p = tracing::span!(Level::INFO, "load_cargo::load_crate_craph/LoadedChanged") + .entered(); for (path, contents) in files { vfs.set_file_contents(path.into(), contents); } diff --git a/crates/proc-macro-api/src/lib.rs b/crates/proc-macro-api/src/lib.rs index c0b27397cb..8749417290 100644 --- a/crates/proc-macro-api/src/lib.rs +++ b/crates/proc-macro-api/src/lib.rs @@ -129,7 +129,7 @@ impl ProcMacroServer { } pub fn load_dylib(&self, dylib: MacroDylib) -> Result, ServerError> { - let _p = tracing::span!(tracing::Level::INFO, "ProcMacroClient::load_dylib").entered(); + let _p = tracing::span!(tracing::Level::INFO, "ProcMacroServer::load_dylib").entered(); let macros = self.process.lock().unwrap_or_else(|e| e.into_inner()).find_proc_macros(&dylib.path)?; diff --git a/crates/rust-analyzer/src/cli/parse.rs b/crates/rust-analyzer/src/cli/parse.rs index ead4d706e6..ed048aa635 100644 --- a/crates/rust-analyzer/src/cli/parse.rs +++ b/crates/rust-analyzer/src/cli/parse.rs @@ -6,7 +6,7 @@ use crate::cli::{flags, read_stdin}; impl flags::Parse { pub fn run(self) -> anyhow::Result<()> { - let _p = tracing::span!(tracing::Level::INFO, "parsing").entered(); + let _p = tracing::span!(tracing::Level::INFO, "flags::Parse::run").entered(); let text = read_stdin()?; let file = SourceFile::parse(&text, Edition::CURRENT).tree(); if !self.no_dump { diff --git a/crates/rust-analyzer/src/handlers/notification.rs b/crates/rust-analyzer/src/handlers/notification.rs index fee8e97273..9d30063ccc 100644 --- a/crates/rust-analyzer/src/handlers/notification.rs +++ b/crates/rust-analyzer/src/handlers/notification.rs @@ -349,7 +349,7 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool { } pub(crate) fn handle_cancel_flycheck(state: &mut GlobalState, _: ()) -> anyhow::Result<()> { - let _p = tracing::span!(tracing::Level::INFO, "handle_stop_flycheck").entered(); + let _p = tracing::span!(tracing::Level::INFO, "handle_cancel_flycheck").entered(); state.flycheck.iter().for_each(|flycheck| flycheck.cancel()); Ok(()) } diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs index 90851ac7c5..5ee0456c15 100644 --- a/crates/rust-analyzer/src/handlers/request.rs +++ b/crates/rust-analyzer/src/handlers/request.rs @@ -1859,7 +1859,7 @@ pub(crate) fn handle_view_recursive_memory_layout( snap: GlobalStateSnapshot, params: lsp_types::TextDocumentPositionParams, ) -> anyhow::Result> { - let _p = tracing::span!(tracing::Level::INFO, "view_recursive_memory_layout").entered(); + let _p = tracing::span!(tracing::Level::INFO, "handle_view_recursive_memory_layout").entered(); let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; let line_index = snap.file_line_index(file_id)?; let offset = from_proto::offset(&line_index, params.position)?;