Skip to content

Commit bdab3e2

Browse files
committed
Improve the clarity of performance logs
1 parent cae621a commit bdab3e2

File tree

8 files changed

+80
-49
lines changed

8 files changed

+80
-49
lines changed

crates/gitbutler-branch-actions/src/actions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ impl VirtualBranchActions {
570570
branch::move_commit(&ctx, target_branch_id, commit_oid).map_err(Into::into)
571571
}
572572

573+
#[instrument(level = tracing::Level::DEBUG, skip(self, project), err(Debug))]
573574
pub fn create_virtual_branch_from_branch(
574575
&self,
575576
project: &Project,

crates/gitbutler-branch-actions/src/branch.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use std::{
2424
fmt::Debug,
2525
vec,
2626
};
27+
use tracing::instrument;
2728

29+
#[instrument(level = tracing::Level::DEBUG, skip(ctx, _permission))]
2830
pub(crate) fn get_uncommited_files_raw(
2931
ctx: &CommandContext,
3032
_permission: &WorktreeReadPermission,

crates/gitbutler-branch-actions/src/branch_manager/branch_creation.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use gitbutler_project::access::WorktreeWritePermission;
99
use gitbutler_reference::{Refname, RemoteRefname};
1010
use gitbutler_repo::{rebase::cherry_rebase, RepoActionsExt, RepositoryExt};
1111
use gitbutler_time::time::now_since_unix_epoch_ms;
12+
use tracing::instrument;
1213

1314
use super::BranchManager;
1415
use crate::{
@@ -20,6 +21,7 @@ use crate::{
2021
};
2122

2223
impl BranchManager<'_> {
24+
#[instrument(level = tracing::Level::DEBUG, skip(self, perm), err(Debug))]
2325
pub fn create_virtual_branch(
2426
&self,
2527
create: &BranchCreateRequest,
@@ -281,6 +283,7 @@ impl BranchManager<'_> {
281283

282284
/// Holding private methods associated to branch creation
283285
impl BranchManager<'_> {
286+
#[instrument(level = tracing::Level::DEBUG, skip(self, perm), err(Debug))]
284287
fn apply_branch(
285288
&self,
286289
branch_id: BranchId,
@@ -310,6 +313,7 @@ impl BranchManager<'_> {
310313
default_target.sha, branch.head
311314
))?;
312315
if merge_base != default_target.sha {
316+
let _span = tracing::debug_span!("merge-base isn't default-target").entered();
313317
// Branch is out of date, merge or rebase it
314318
let merge_base_tree = repo
315319
.find_commit(merge_base)
@@ -454,6 +458,8 @@ impl BranchManager<'_> {
454458
vb_state.set_branch(branch.clone())?;
455459
}
456460

461+
let _span = tracing::debug_span!("finalize").entered();
462+
457463
let wd_tree = self.ctx.repository().create_wd_tree()?;
458464

459465
let branch_tree = repo

crates/gitbutler-branch-actions/src/branch_manager/branch_removal.rs

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use gitbutler_oplog::SnapshotExt;
88
use gitbutler_project::access::WorktreeWritePermission;
99
use gitbutler_reference::{normalize_branch_name, ReferenceName, Refname};
1010
use gitbutler_repo::{RepoActionsExt, RepositoryExt};
11+
use tracing::instrument;
1112

1213
use super::BranchManager;
1314
use crate::{
@@ -19,6 +20,7 @@ use crate::{
1920

2021
impl BranchManager<'_> {
2122
// to unapply a branch, we need to write the current tree out, then remove those file changes from the wd
23+
#[instrument(level = tracing::Level::DEBUG, skip(self, perm), err(Debug))]
2224
pub fn convert_to_real_branch(
2325
&self,
2426
branch_id: BranchId,
@@ -52,6 +54,7 @@ impl BranchManager<'_> {
5254
real_branch.reference_name()
5355
}
5456

57+
#[instrument(level = tracing::Level::DEBUG, skip(self, perm), err(Debug))]
5558
pub(crate) fn delete_branch(
5659
&self,
5760
branch_id: BranchId,
@@ -88,30 +91,38 @@ impl BranchManager<'_> {
8891

8992
// go through the other applied branches and merge them into the final tree
9093
// then check that out into the working directory
91-
let final_tree = applied_statuses
92-
.into_iter()
93-
.filter(|(branch, _)| branch.id != branch_id)
94-
.fold(
95-
target_commit.tree().context("failed to get target tree"),
96-
|final_tree, status| {
97-
let final_tree = final_tree?;
98-
let branch = status.0;
99-
let files = status
100-
.1
101-
.into_iter()
102-
.map(|file| (file.path, file.hunks))
103-
.collect::<Vec<(PathBuf, Vec<VirtualBranchHunk>)>>();
104-
let tree_oid =
105-
gitbutler_diff::write::hunks_onto_oid(self.ctx, branch.head, files)?;
106-
let branch_tree = repo.find_tree(tree_oid)?;
107-
let mut result =
108-
repo.merge_trees(&base_tree, &final_tree, &branch_tree, None)?;
109-
let final_tree_oid = result.write_tree_to(repo)?;
110-
repo.find_tree(final_tree_oid)
111-
.context("failed to find tree")
112-
},
113-
)?;
94+
let final_tree = {
95+
let _span = tracing::debug_span!(
96+
"new tree without deleted branch",
97+
num_branches = applied_statuses.len() - 1
98+
)
99+
.entered();
100+
applied_statuses
101+
.into_iter()
102+
.filter(|(branch, _)| branch.id != branch_id)
103+
.fold(
104+
target_commit.tree().context("failed to get target tree"),
105+
|final_tree, status| {
106+
let final_tree = final_tree?;
107+
let branch = status.0;
108+
let files = status
109+
.1
110+
.into_iter()
111+
.map(|file| (file.path, file.hunks))
112+
.collect::<Vec<(PathBuf, Vec<VirtualBranchHunk>)>>();
113+
let tree_oid =
114+
gitbutler_diff::write::hunks_onto_oid(self.ctx, branch.head, files)?;
115+
let branch_tree = repo.find_tree(tree_oid)?;
116+
let mut result =
117+
repo.merge_trees(&base_tree, &final_tree, &branch_tree, None)?;
118+
let final_tree_oid = result.write_tree_to(repo)?;
119+
repo.find_tree(final_tree_oid)
120+
.context("failed to find tree")
121+
},
122+
)?
123+
};
114124

125+
let _span = tracing::debug_span!("checkout final tree").entered();
115126
// checkout final_tree into the working directory
116127
repo.checkout_tree_builder(&final_tree)
117128
.force()
@@ -128,6 +139,7 @@ impl BranchManager<'_> {
128139
}
129140

130141
impl BranchManager<'_> {
142+
#[instrument(level = tracing::Level::DEBUG, skip(self, vbranch), err(Debug))]
131143
fn build_real_branch(&self, vbranch: &mut Branch) -> Result<git2::Branch<'_>> {
132144
let repo = self.ctx.repository();
133145
let target_commit = repo.find_commit(vbranch.head)?;

crates/gitbutler-branch-actions/src/integration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ fn write_integration_file(head: &git2::Reference, path: PathBuf) -> Result<()> {
122122
std::fs::write(path, format!(":{}", sha))?;
123123
Ok(())
124124
}
125+
#[instrument(level = tracing::Level::DEBUG, skip(vb_state, ctx), err(Debug))]
125126
pub fn update_gitbutler_integration(
126127
vb_state: &VirtualBranchesHandle,
127128
ctx: &CommandContext,

crates/gitbutler-branch-actions/src/virtual.rs

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ fn find_base_tree<'a>(
232232
/// This should only ever be called by `list_virtual_branches
233233
///
234234
/// This checks for the case where !branch.old_applied && branch.in_workspace
235-
/// If this is the case, we ought to unapply the branch as its been carried
235+
/// If this is the case, we ought to unapply the branch as it has been carried
236236
/// over from the old style of unapplying
237-
fn resolve_old_applied_state(
237+
fn fixup_old_applied_state(
238238
ctx: &CommandContext,
239239
vb_state: &VirtualBranchesHandle,
240240
perm: &mut WorktreeWritePermission,
@@ -278,7 +278,7 @@ pub fn list_virtual_branches_cached(
278278

279279
let vb_state = ctx.project().virtual_branches();
280280

281-
resolve_old_applied_state(ctx, &vb_state, perm)?;
281+
fixup_old_applied_state(ctx, &vb_state, perm)?;
282282

283283
let default_target = vb_state
284284
.get_default_target()
@@ -292,6 +292,8 @@ pub fn list_virtual_branches_cached(
292292
.max()
293293
.unwrap_or(-1);
294294

295+
let branches_span =
296+
tracing::debug_span!("handle branches", num_branches = status.branches.len()).entered();
295297
for (branch, mut files) in status.branches {
296298
let repo = ctx.repository();
297299
update_conflict_markers(ctx, files.clone())?;
@@ -331,23 +333,31 @@ pub fn list_virtual_branches_cached(
331333
// find all commits on head that are not on target.sha
332334
let commits = ctx.log(branch.head, LogUntil::Commit(default_target.sha))?;
333335
let check_commit = IsCommitIntegrated::new(ctx, &default_target)?;
334-
let vbranch_commits = commits
335-
.iter()
336-
.map(|commit| {
337-
is_remote = if is_remote {
338-
is_remote
339-
} else {
340-
pushed_commits.contains_key(&commit.id())
341-
};
342-
343-
// only check for integration if we haven't already found an integration
344-
if !is_integrated {
345-
is_integrated = check_commit.is_integrated(commit)?
346-
};
347-
348-
commit_to_vbranch_commit(ctx, &branch, commit, is_integrated, is_remote)
349-
})
350-
.collect::<Result<Vec<_>>>()?;
336+
let vbranch_commits = {
337+
let _span = tracing::debug_span!(
338+
"is-commit-integrated",
339+
given_name = branch.name,
340+
commits_to_check = commits.len()
341+
)
342+
.entered();
343+
commits
344+
.iter()
345+
.map(|commit| {
346+
is_remote = if is_remote {
347+
is_remote
348+
} else {
349+
pushed_commits.contains_key(&commit.id())
350+
};
351+
352+
// only check for integration if we haven't already found an integration
353+
if !is_integrated {
354+
is_integrated = check_commit.is_integrated(commit)?
355+
};
356+
357+
commit_to_vbranch_commit(ctx, &branch, commit, is_integrated, is_remote)
358+
})
359+
.collect::<Result<Vec<_>>>()?
360+
};
351361

352362
let merge_base = repo
353363
.merge_base(default_target.sha, branch.head)
@@ -409,6 +419,7 @@ pub fn list_virtual_branches_cached(
409419
};
410420
branches.push(branch);
411421
}
422+
drop(branches_span);
412423

413424
let mut branches = branches_with_large_files_abridged(branches);
414425
branches.sort_by(|a, b| a.order.cmp(&b.order));

crates/gitbutler-diff/src/diff.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ pub fn workdir(repo: &git2::Repository, commit_oid: git2::Oid) -> Result<DiffByP
162162
}
163163

164164
pub fn trees(
165-
repository: &git2::Repository,
165+
repo: &git2::Repository,
166166
old_tree: &git2::Tree,
167167
new_tree: &git2::Tree,
168168
) -> Result<DiffByPathMap> {
@@ -175,10 +175,7 @@ pub fn trees(
175175
.context_lines(3)
176176
.show_untracked_content(true);
177177

178-
// This is not a content-based diff, but also considers modification times apparently,
179-
// maybe related to racy-git. This is why empty diffs have ot be filtered.
180-
let diff =
181-
repository.diff_tree_to_tree(Some(old_tree), Some(new_tree), Some(&mut diff_opts))?;
178+
let diff = repo.diff_tree_to_tree(Some(old_tree), Some(new_tree), Some(&mut diff_opts))?;
182179
hunks_by_filepath(None, &diff)
183180
}
184181

crates/gitbutler-oplog/src/oplog.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl OplogExt for Project {
148148
commit_snapshot(self, snapshot_tree_id, details, perm)
149149
}
150150

151-
#[instrument(skip(details, perm), err(Debug))]
151+
#[instrument(skip(self, details, perm), err(Debug))]
152152
fn create_snapshot(
153153
&self,
154154
details: SnapshotDetails,
@@ -158,6 +158,7 @@ impl OplogExt for Project {
158158
commit_snapshot(self, tree_id, details, perm)
159159
}
160160

161+
#[instrument(skip(self), err(Debug))]
161162
fn list_snapshots(
162163
&self,
163164
limit: usize,

0 commit comments

Comments
 (0)