From 018bb88ec63e214e7e4501748db2e3c253a04273 Mon Sep 17 00:00:00 2001 From: Waleed Khan Date: Tue, 25 Jul 2023 21:31:05 +0300 Subject: [PATCH] perf: add several `#[instrument]`s --- lib/src/fsmonitor.rs | 4 +++- lib/src/lock/fallback.rs | 2 ++ lib/src/lock/unix.rs | 2 ++ lib/src/matchers.rs | 3 +++ lib/src/repo.rs | 1 + lib/src/working_copy.rs | 5 +++++ src/cleanup_guard.rs | 2 ++ src/cli_util.rs | 2 ++ src/commands/mod.rs | 1 + src/config.rs | 1 + src/diff_util.rs | 2 ++ src/ui.rs | 2 ++ 12 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/src/fsmonitor.rs b/lib/src/fsmonitor.rs index 665cea1a8..75f91ab63 100644 --- a/lib/src/fsmonitor.rs +++ b/lib/src/fsmonitor.rs @@ -62,7 +62,7 @@ pub mod watchman { use itertools::Itertools; use thiserror::Error; - use tracing::info; + use tracing::{info, instrument}; use watchman_client::prelude::{ Clock as InnerClock, ClockSpec, NameOnly, QueryRequestCommon, QueryResult, }; @@ -142,6 +142,7 @@ pub mod watchman { /// running, this will start it and have it crawl the working /// copy to build up its in-memory representation of the /// filesystem, which may take some time. + #[instrument] pub async fn init(working_copy_path: &Path) -> Result { info!("Initializing Watchman filesystem monitor..."); let connector = watchman_client::Connector::new(); @@ -165,6 +166,7 @@ pub mod watchman { /// /// The returned list of paths is absolute. If it is `None`, then the /// caller must crawl the entire working copy themselves. + #[instrument(skip(self))] pub async fn query_changed_files( &self, previous_clock: Option, diff --git a/lib/src/lock/fallback.rs b/lib/src/lock/fallback.rs index 56e9ac2af..154549c61 100644 --- a/lib/src/lock/fallback.rs +++ b/lib/src/lock/fallback.rs @@ -17,6 +17,7 @@ use std::path::PathBuf; use std::time::Duration; use backoff::{retry, ExponentialBackoff}; +use tracing::instrument; pub struct FileLock { path: PathBuf, @@ -64,6 +65,7 @@ impl FileLock { } impl Drop for FileLock { + #[instrument(skip_all)] fn drop(&mut self) { std::fs::remove_file(&self.path).expect("failed to delete lock file"); } diff --git a/lib/src/lock/unix.rs b/lib/src/lock/unix.rs index cf77d12cc..1f65e3a02 100644 --- a/lib/src/lock/unix.rs +++ b/lib/src/lock/unix.rs @@ -18,6 +18,7 @@ use std::fs::File; use std::path::PathBuf; use rustix::fs::FlockOperation; +use tracing::instrument; pub struct FileLock { path: PathBuf, @@ -48,6 +49,7 @@ impl FileLock { } impl Drop for FileLock { + #[instrument(skip_all)] fn drop(&mut self) { // Removing the file isn't strictly necessary, but reduces confusion. _ = std::fs::remove_file(&self.path); diff --git a/lib/src/matchers.rs b/lib/src/matchers.rs index f61cafded..5cfa5965d 100644 --- a/lib/src/matchers.rs +++ b/lib/src/matchers.rs @@ -17,6 +17,8 @@ use std::collections::{HashMap, HashSet}; use std::iter; +use tracing::instrument; + use crate::repo_path::{RepoPath, RepoPathComponent}; #[derive(PartialEq, Eq, Debug)] @@ -126,6 +128,7 @@ pub struct PrefixMatcher { } impl PrefixMatcher { + #[instrument] pub fn new(prefixes: &[RepoPath]) -> Self { let mut tree = RepoPathTree::new(); for prefix in prefixes { diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 74a7e45df..69c7837b0 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -303,6 +303,7 @@ impl ReadonlyRepo { self.loader().load_at_head(user_settings) } + #[instrument] pub fn reload_at(&self, operation: &Operation) -> Result, RepoLoaderError> { self.loader().load_at(operation) } diff --git a/lib/src/working_copy.rs b/lib/src/working_copy.rs index 7101bf451..a0486234f 100644 --- a/lib/src/working_copy.rs +++ b/lib/src/working_copy.rs @@ -574,6 +574,7 @@ impl TreeState { #[cfg(feature = "watchman")] #[tokio::main] + #[instrument(skip(self))] pub async fn query_watchman( &self, ) -> Result<(watchman::Clock, Option>), TreeStateError> { @@ -704,6 +705,7 @@ impl TreeState { Ok(has_changes || fsmonitor_clock_needs_save) } + #[instrument(skip_all)] fn make_fsmonitor_matcher( &mut self, fsmonitor_kind: Option, @@ -1311,6 +1313,7 @@ impl WorkingCopy { &self.checkout_state().workspace_id } + #[instrument(skip_all)] fn tree_state(&self) -> Result<&TreeState, TreeStateError> { self.tree_state.get_or_try_init(|| { TreeState::load( @@ -1338,6 +1341,7 @@ impl WorkingCopy { Ok(self.tree_state()?.sparse_patterns()) } + #[instrument(skip_all)] fn save(&mut self) { self.write_proto(crate::protos::working_copy::Checkout { operation_id: self.operation_id().to_bytes(), @@ -1468,6 +1472,7 @@ impl LockedWorkingCopy<'_> { Ok(stats) } + #[instrument(skip_all)] pub fn finish(mut self, operation_id: OperationId) -> Result<(), TreeStateError> { assert!(self.tree_state_dirty || &self.old_tree_id == self.wc.current_tree_id()?); if self.tree_state_dirty { diff --git a/src/cleanup_guard.rs b/src/cleanup_guard.rs index 7de2e4358..2edb1fea9 100644 --- a/src/cleanup_guard.rs +++ b/src/cleanup_guard.rs @@ -3,6 +3,7 @@ use std::sync::{Mutex, Once}; use once_cell::sync::Lazy; use slab::Slab; +use tracing::instrument; /// Contains the callbacks passed to currently-live [`CleanupGuard`]s static LIVE_GUARDS: Lazy> = Lazy::new(|| Mutex::new(Slab::new())); @@ -36,6 +37,7 @@ impl CleanupGuard { } impl Drop for CleanupGuard { + #[instrument(skip_all)] fn drop(&mut self) { let guards = &mut *LIVE_GUARDS.lock().unwrap(); let f = guards.remove(self.slot); diff --git a/src/cli_util.rs b/src/cli_util.rs index a73577613..849933af0 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -914,6 +914,7 @@ impl WorkspaceCommandHelper { } } + #[instrument(skip_all)] pub fn base_ignores(&self) -> Arc { fn xdg_config_home() -> Result { if let Ok(x) = std::env::var("XDG_CONFIG_HOME") { @@ -1540,6 +1541,7 @@ pub enum StaleWorkingCopyError { UnrelatedOperation, } +#[instrument(skip_all)] pub fn check_stale_working_copy( locked_wc: &LockedWorkingCopy, wc_commit: &Commit, diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 2973fb49b..6af9cadaf 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -3673,6 +3673,7 @@ pub fn default_app() -> Command { Commands::augment_subcommands(Args::command()) } +#[instrument(skip_all)] pub fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), CommandError> { let derived_subcommands: Commands = Commands::from_arg_matches(command_helper.matches()).unwrap(); diff --git a/src/config.rs b/src/config.rs index eb8185f75..11451b817 100644 --- a/src/config.rs +++ b/src/config.rs @@ -85,6 +85,7 @@ impl LayeredConfigs { } } + #[instrument] pub fn read_user_config(&mut self) -> Result<(), ConfigError> { self.user = existing_config_path()? .map(|path| read_config_path(&path)) diff --git a/src/diff_util.rs b/src/diff_util.rs index 2f068faaa..909d52c1e 100644 --- a/src/diff_util.rs +++ b/src/diff_util.rs @@ -28,6 +28,7 @@ use jj_lib::repo_path::RepoPath; use jj_lib::settings::UserSettings; use jj_lib::tree::{Tree, TreeDiffIterator}; use jj_lib::{diff, files, rewrite, tree}; +use tracing::instrument; use crate::cli_util::{CommandError, WorkspaceCommandHelper}; use crate::formatter::Formatter; @@ -671,6 +672,7 @@ pub fn show_git_diff( Ok(()) } +#[instrument(skip_all)] pub fn show_diff_summary( formatter: &mut dyn Formatter, workspace_command: &WorkspaceCommandHelper, diff --git a/src/ui.rs b/src/ui.rs index 2dc40a312..363549261 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -245,6 +245,7 @@ impl Ui { } /// Waits for the pager exits. + #[instrument(skip_all)] pub fn finalize_pager(&mut self) { if let UiOutput::Paged { mut child, @@ -351,6 +352,7 @@ pub struct OutputGuard { } impl Drop for OutputGuard { + #[instrument(skip_all)] fn drop(&mut self) { _ = self.output.write_all(self.text.as_bytes()); _ = self.output.flush();