ztracing: Annotate more callsites that invoke TreeSitter (#47522)

Jakub Konka created

Release Notes:

- N/A

Change summary

crates/git_ui/src/file_diff_view.rs      | 2 ++
crates/language/src/buffer.rs            | 2 ++
crates/language/src/language.rs          | 1 +
crates/language/src/language_registry.rs | 1 +
crates/language/src/syntax_map.rs        | 2 ++
crates/ztracing/src/lib.rs               | 8 ++++++--
6 files changed, 14 insertions(+), 2 deletions(-)

Detailed changes

crates/git_ui/src/file_diff_view.rs 🔗

@@ -36,6 +36,7 @@ pub struct FileDiffView {
 const RECALCULATE_DIFF_DEBOUNCE: Duration = Duration::from_millis(250);
 
 impl FileDiffView {
+    #[ztracing::instrument(skip_all)]
     pub fn open(
         old_path: PathBuf,
         new_path: PathBuf,
@@ -162,6 +163,7 @@ impl FileDiffView {
     }
 }
 
+#[ztracing::instrument(skip_all)]
 async fn build_buffer_diff(
     old_buffer: &Entity<Buffer>,
     new_buffer: &Entity<Buffer>,

crates/language/src/buffer.rs 🔗

@@ -1158,6 +1158,7 @@ impl Buffer {
         }
     }
 
+    #[ztracing::instrument(skip_all)]
     pub fn build_snapshot(
         text: Rope,
         language: Option<Arc<Language>>,
@@ -1300,6 +1301,7 @@ impl Buffer {
         })
     }
 
+    #[ztracing::instrument(skip_all)]
     pub fn preview_edits(
         &self,
         edits: Arc<[(Range<Anchor>, Arc<str>)]>,

crates/language/src/language.rs 🔗

@@ -97,6 +97,7 @@ pub use tree_sitter::{Node, Parser, Tree, TreeCursor};
 static QUERY_CURSORS: Mutex<Vec<QueryCursor>> = Mutex::new(vec![]);
 static PARSERS: Mutex<Vec<Parser>> = Mutex::new(vec![]);
 
+#[ztracing::instrument(skip_all)]
 pub fn with_parser<F, R>(func: F) -> R
 where
     F: FnOnce(&mut Parser) -> R,

crates/language/src/language_registry.rs 🔗

@@ -741,6 +741,7 @@ impl LanguageRegistry {
         self.language_for_file_internal(path, None, None)
     }
 
+    #[ztracing::instrument(skip_all)]
     pub fn load_language_for_file_path<'a>(
         self: &Arc<Self>,
         path: &'a Path,

crates/language/src/syntax_map.rs 🔗

@@ -416,6 +416,7 @@ impl SyntaxSnapshot {
         self.layers = layers;
     }
 
+    #[ztracing::instrument(skip_all)]
     pub fn reparse(
         &mut self,
         text: &BufferSnapshot,
@@ -425,6 +426,7 @@ impl SyntaxSnapshot {
         self.reparse_(text, registry, root_language, None).ok();
     }
 
+    #[ztracing::instrument(skip_all)]
     pub fn reparse_with_timeout(
         &mut self,
         text: &BufferSnapshot,

crates/ztracing/src/lib.rs 🔗

@@ -4,13 +4,17 @@ pub use tracing::{Level, field};
 pub use tracing::{
     Span, debug_span, error_span, event, info_span, instrument, span, trace_span, warn_span,
 };
+
 #[cfg(not(ztracing))]
 pub use ztracing_macro::instrument;
 
+#[cfg(ztracing)]
+const MAX_CALLSTACK_DEPTH: u16 = 16;
+
 #[cfg(all(ztracing, ztracing_with_memory))]
 #[global_allocator]
 static GLOBAL: tracy_client::ProfiledAllocator<std::alloc::System> =
-    tracy_client::ProfiledAllocator::new(std::alloc::System, 100);
+    tracy_client::ProfiledAllocator::new(std::alloc::System, MAX_CALLSTACK_DEPTH);
 
 #[cfg(not(ztracing))]
 pub use __consume_all_tokens as trace_span;
@@ -67,7 +71,7 @@ pub fn init() {
         }
 
         fn stack_depth(&self, _: &tracing::Metadata) -> u16 {
-            8
+            MAX_CALLSTACK_DEPTH
         }
 
         fn format_fields_in_zone_name(&self) -> bool {