Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tracing logs around git dirty hashes listing #344

Merged
merged 5 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions crates/atlaspack_vcs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ use std::{
hash::{Hash, Hasher},
path::{Path, PathBuf},
process::Command,
time::Instant,
};
use yarn_integration::{parse_yarn_lock, parse_yarn_state_file, YarnLock, YarnStateFile};

Expand All @@ -138,30 +139,46 @@ pub mod yarn_integration;
pub struct VCSState {
pub git_hash: String,
pub dirty_files: Vec<VCSFile>,
pub dirty_files_execution_time: u32,
pub yarn_states: Vec<YarnSnapshot>,
}

impl VCSState {
/// Read the VCS state from a repository root. Ignore dirty files matching
/// the exclude patterns.
#[tracing::instrument(level = "info", skip_all)]
pub fn read_from_repository(
path: &Path,
exclude_patterns: &[String],
failure_mode: FailureMode,
) -> anyhow::Result<VCSState> {
tracing::info!("Reading VCS state");
let span = tracing::span!(tracing::Level::INFO, "vcs_dirty_files_duration");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just #[tracing::instrument] the vcs_list_dirty_files function instead, which would do pretty much this code (but also end the span when the function is over.

let _enter = span.enter();
let start_time = Instant::now();

let repo = Repository::open(path)?;
let head = repo.revparse_single("HEAD")?.peel_to_commit()?;
let git_hash = head.id().to_string();
tracing::info!("Found head commit");
let file_listing = vcs_list_dirty_files(path, exclude_patterns)?;
let files_listing_duration = start_time
.elapsed()
.as_millis()
.try_into()
.unwrap_or(u32::MAX);
tracing::info!(
"vcs_list_dirty_files executed in: {:?}",
files_listing_duration
);
tracing::info!("Listed dirty files");
let yarn_states = list_yarn_states(path, failure_mode)?;
tracing::info!("Listed yarn states");

Ok(VCSState {
git_hash,
dirty_files: file_listing,
dirty_files_execution_time: files_listing_duration,
yarn_states,
})
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/rust/index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ export interface YarnState {

export interface VCSState {
gitHash: string;
// Files that have been modified since the last commit
dirtyFiles: VCSFile[];
yarnStates: YarnState[];
}
Expand Down