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.)
This commit is contained in:
Wilfred Hughes 2024-04-26 17:00:58 -07:00
parent 1bf1f6e0a1
commit c981ff0944
20 changed files with 31 additions and 31 deletions

View file

@ -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);

View file

@ -82,7 +82,7 @@ fn toolchain_channel(db: &dyn SourceDatabase, krate: CrateId) -> Option<ReleaseC
}
fn parse(db: &dyn SourceDatabase, file_id: FileId) -> Parse<ast::SourceFile> {
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)

View file

@ -806,7 +806,7 @@ pub(crate) fn impl_datum_query(
krate: CrateId,
impl_id: ImplId,
) -> Arc<ImplDatum> {
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_)

View file

@ -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();

View file

@ -4503,7 +4503,8 @@ impl Type {
name: Option<&Name>,
mut callback: impl FnMut(Function) -> Option<T>,
) -> Option<T> {
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(

View file

@ -723,7 +723,7 @@ impl<'db> SemanticsImpl<'db> {
mut token: SyntaxToken,
f: &mut dyn FnMut(InFile<SyntaxToken>) -> 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<TextSize>,
infer_body: bool,
) -> Option<SourceAnalyzer> {
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))?;

View file

@ -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

View file

@ -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)?;

View file

@ -368,7 +368,7 @@ fn render_resolution_pat(
import_to_add: Option<LocatedImport>,
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<LocatedImport>,
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<LocatedImport>,
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);

View file

@ -27,7 +27,7 @@ pub(crate) fn render_variant_lit(
variant: hir::Variant,
path: Option<hir::ModPath>,
) -> Option<Builder> {
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));

View file

@ -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_)
}

View file

@ -209,8 +209,7 @@ impl ImportAssets {
prefer_no_std: bool,
prefer_prelude: bool,
) -> impl Iterator<Item = LocatedImport> {
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<Item = LocatedImport> {
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<Item = LocatedImport> {
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<ScopeDef> {
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<LocatedImport> {
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<LocatedImport> {
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<ModPath>,
scope_filter: impl Fn(hir::Trait) -> bool,
) -> FxHashSet<LocatedImport> {
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;

View file

@ -194,7 +194,7 @@ fn insert_use_with_alias_option(
cfg: &InsertUseConfig,
alias: Option<ast::Rename>,
) {
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),

View file

@ -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 = {

View file

@ -496,7 +496,7 @@ pub(crate) fn inlay_hints_resolve(
config: &InlayHintsConfig,
hasher: impl Fn(&InlayHint) -> u64,
) -> Option<InlayHint> {
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();

View file

@ -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);
}

View file

@ -129,7 +129,7 @@ impl ProcMacroServer {
}
pub fn load_dylib(&self, dylib: MacroDylib) -> Result<Vec<ProcMacro>, 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)?;

View file

@ -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 {

View file

@ -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(())
}

View file

@ -1859,7 +1859,7 @@ pub(crate) fn handle_view_recursive_memory_layout(
snap: GlobalStateSnapshot,
params: lsp_types::TextDocumentPositionParams,
) -> anyhow::Result<Option<lsp_ext::RecursiveMemoryLayout>> {
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, &params.text_document.uri)?;
let line_index = snap.file_line_index(file_id)?;
let offset = from_proto::offset(&line_index, params.position)?;