perf: add several #[instrument]s

This commit is contained in:
Waleed Khan 2023-07-25 21:31:05 +03:00 committed by Martin von Zweigbergk
parent 7875656354
commit 018bb88ec6
12 changed files with 26 additions and 1 deletions

View file

@ -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<Self, Error> {
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<Clock>,

View file

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

View file

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

View file

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

View file

@ -303,6 +303,7 @@ impl ReadonlyRepo {
self.loader().load_at_head(user_settings)
}
#[instrument]
pub fn reload_at(&self, operation: &Operation) -> Result<Arc<ReadonlyRepo>, RepoLoaderError> {
self.loader().load_at(operation)
}

View file

@ -574,6 +574,7 @@ impl TreeState {
#[cfg(feature = "watchman")]
#[tokio::main]
#[instrument(skip(self))]
pub async fn query_watchman(
&self,
) -> Result<(watchman::Clock, Option<Vec<PathBuf>>), 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<FsmonitorKind>,
@ -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 {

View file

@ -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<Mutex<GuardTable>> = 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);

View file

@ -914,6 +914,7 @@ impl WorkspaceCommandHelper {
}
}
#[instrument(skip_all)]
pub fn base_ignores(&self) -> Arc<GitIgnoreFile> {
fn xdg_config_home() -> Result<PathBuf, VarError> {
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,

View file

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

View file

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

View file

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

View file

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