Skip to content

Commit 3cffa26

Browse files
committed
feat: provide basic tracing spans for common operations.
This is just the beginning and more crates will integrate with it over time.
1 parent 093efaf commit 3cffa26

File tree

18 files changed

+25
-1
lines changed

18 files changed

+25
-1
lines changed

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
rustflags = [
33
# Rustc lints
44
# "-W", "warning_name"
5-
# "-A", "warning_name"
5+
"-A", "clippy::let_unit_value", # in 'small' builds this triggers as the `span!` macro yields `let x = ()`. No way to prevent it in macro apparently.
66

77
# Clippy lints
88
"-W", "clippy::cloned_instead_of_copied",

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gix-index/src/decode/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ impl State {
6565
expected_checksum,
6666
}: Options,
6767
) -> Result<(Self, gix_hash::ObjectId), Error> {
68+
let _span = gix_features::trace::detail!("gix_index::State::from_bytes()");
6869
let (version, num_entries, post_header_data) = header::decode(data, object_hash)?;
6970
let start_of_extensions = extension::end_of_index_entry::decode(data, object_hash);
7071

gix-index/src/file/init.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl File {
4646

4747
/// Open an index file at `path` with `options`, assuming `object_hash` is used throughout the file.
4848
pub fn at(path: impl Into<PathBuf>, object_hash: gix_hash::Kind, options: decode::Options) -> Result<Self, Error> {
49+
let _span = gix_features::trace::detail!("gix_index::File::at()");
4950
let path = path.into();
5051
let (data, mtime) = {
5152
// SAFETY: we have to take the risk of somebody changing the file underneath. Git never writes into the same file.

gix-index/src/write.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub struct Options {
5555
impl State {
5656
/// Serialize this instance to `out` with [`options`][Options].
5757
pub fn write_to(&self, out: impl std::io::Write, Options { extensions }: Options) -> std::io::Result<Version> {
58+
let _span = gix_features::trace::detail!("gix_index::State::write()");
5859
let version = self.detect_required_version();
5960

6061
let mut write = CountBytes::new(out);

gix-odb/src/store_impls/dynamic/init.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ impl Store {
7979
current_dir,
8080
}: Options,
8181
) -> std::io::Result<Self> {
82+
let _span = gix_features::trace::detail!("gix_odb::Store::at()");
8283
let objects_dir = objects_dir.into();
8384
let current_dir = current_dir.map_or_else(std::env::current_dir, Ok)?;
8485
if !objects_dir.is_dir() {

gix-odb/src/store_impls/dynamic/prefix.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ where
8585
match *count {
8686
Some(count) => Ok(count),
8787
None => {
88+
let _span = gix_features::trace::detail!("gix_odb::Handle::packed_object_count()");
8889
let mut snapshot = self.snapshot.borrow_mut();
8990
*snapshot = self.store.load_all_indices()?;
9091
let mut obj_count = 0;

gix-odb/src/store_impls/dynamic/structure.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ impl Store {
5252
/// implementation. The likelihood of actual changes is low though as these still depend on something
5353
/// changing on disk and somebody reading at the same time.
5454
pub fn structure(&self) -> Result<Vec<Record>, load_index::Error> {
55+
let _span = gix_features::trace::detail!("gix_odb::Store::structure()");
5556
let index = self.index.load();
5657
if !index.is_initialized() {
5758
self.consolidate_with_disk_state(true, false /*load one new index*/)?;

gix-pack/src/bundle/write/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ impl crate::Bundle {
7070
thin_pack_base_object_lookup_fn: Option<ThinPackLookupFn>,
7171
options: Options,
7272
) -> Result<Outcome, Error> {
73+
let _span = gix_features::trace::coarse!("gix_pack::Bundle::write_to_directory()");
7374
let mut read_progress = progress.add_child_with_id("read pack", ProgressId::ReadPackBytes.into());
7475
read_progress.init(None, progress::bytes());
7576
let pack = progress::Read {
@@ -183,6 +184,7 @@ impl crate::Bundle {
183184
P: Progress,
184185
P::SubProgress: 'static,
185186
{
187+
let _span = gix_features::trace::coarse!("gix_pack::Bundle::write_to_directory_eagerly()");
186188
let mut read_progress = progress.add_child_with_id("read pack", ProgressId::ReadPackBytes.into()); /* Bundle Write Read pack Bytes*/
187189
read_progress.init(pack_size.map(|s| s as usize), progress::bytes());
188190
let pack = progress::Read {

gix-path/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rust-version = "1.64"
1313
doctest = false
1414

1515
[dependencies]
16+
gix-trace = { version = "0.1.0", path = "../gix-trace" }
1617
bstr = { version = "1.3.0", default-features = false, features = ["std"] }
1718
thiserror = "1.0.26"
1819
once_cell = "1.17.1"

gix-path/src/env/git.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use bstr::{BStr, BString, ByteSlice};
88
/// Returns the file that contains git configuration coming with the installation of the `git` file in the current `PATH`, or `None`
99
/// if no `git` executable was found or there were other errors during execution.
1010
pub(crate) fn install_config_path() -> Option<&'static BStr> {
11+
let _span = gix_trace::detail!("gix_path::git::install_config_path()");
1112
static PATH: once_cell::sync::Lazy<Option<BString>> = once_cell::sync::Lazy::new(|| {
1213
// Shortcut: in Msys shells this variable is set which allows to deduce the installation directory
1314
// so we can save the `git` invocation.

gix/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ gix-transport = { version = "^0.32.0", path = "../gix-transport", optional = tru
141141
gix-diff = { version = "^0.30.1", path = "../gix-diff" }
142142
gix-mailmap = { version = "^0.13.0", path = "../gix-mailmap" }
143143
gix-features = { version = "^0.30.0", path = "../gix-features", features = ["progress", "once_cell"] }
144+
gix-trace = { version = "^0.1.0", path = "../gix-trace" }
144145

145146
gix-attributes = { version = "^0.13.1", path = "../gix-attributes" }
146147
gix-ignore = { version = "^0.3.0", path = "../gix-ignore" }

gix/src/clone/checkout.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub mod main_worktree {
6969
mut progress: impl crate::Progress,
7070
should_interrupt: &AtomicBool,
7171
) -> Result<(Repository, gix_worktree::checkout::Outcome), Error> {
72+
let _span = gix_trace::coarse!("gix::clone::PrepareCheckout::main_worktree()");
7273
let repo = self
7374
.repo
7475
.as_ref()

gix/src/discover.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ impl ThreadSafeRepository {
3636
options: upwards::Options<'_>,
3737
trust_map: gix_sec::trust::Mapping<crate::open::Options>,
3838
) -> Result<Self, Error> {
39+
let _span = gix_trace::coarse!("ThreadSafeRepository::discover()");
3940
let (path, trust) = upwards_opts(directory, options)?;
4041
let (git_dir, worktree_dir) = path.into_repository_and_work_tree_directories();
4142
let mut options = trust_map.into_value_by_level(trust);

gix/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pub use gix_ref as refs;
9393
pub use gix_refspec as refspec;
9494
pub use gix_sec as sec;
9595
pub use gix_tempfile as tempfile;
96+
pub use gix_trace as trace;
9697
pub use gix_traverse as traverse;
9798
pub use gix_url as url;
9899
#[doc(inline)]

gix/src/open/repository.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ impl ThreadSafeRepository {
5151
///
5252
/// Note that you should use [`crate::discover()`] if security should be adjusted by ownership.
5353
pub fn open_opts(path: impl Into<PathBuf>, mut options: Options) -> Result<Self, Error> {
54+
let _span = gix_trace::coarse!("ThreadSafeRepository::open()");
5455
let (path, kind) = {
5556
let path = path.into();
5657
let looks_like_git_dir =
@@ -103,6 +104,7 @@ impl ThreadSafeRepository {
103104
fallback_directory: impl Into<PathBuf>,
104105
trust_map: gix_sec::trust::Mapping<Options>,
105106
) -> Result<Self, Error> {
107+
let _span = gix_trace::coarse!("ThreadSafeRepository::open_with_environment_overrides()");
106108
let overrides = EnvironmentOverrides::from_env()?;
107109
let (path, path_kind): (PathBuf, _) = match overrides.git_dir {
108110
Some(git_dir) => gix_discover::is_git(&git_dir)
@@ -139,6 +141,7 @@ impl ThreadSafeRepository {
139141
mut worktree_dir: Option<PathBuf>,
140142
options: Options,
141143
) -> Result<Self, Error> {
144+
let _span = gix_trace::detail!("open_from_paths()");
142145
let Options {
143146
git_dir_trust,
144147
object_store_slots,
@@ -238,6 +241,7 @@ impl ThreadSafeRepository {
238241
refs.write_reflog = config::cache::util::reflog_or_default(config.reflog, worktree_dir.is_some());
239242
let replacements = replacement_objects_refs_prefix(&config.resolved, lenient_config, filter_config_section)?
240243
.and_then(|prefix| {
244+
let _span = gix_trace::detail!("find replacement objects");
241245
let platform = refs.iter().ok()?;
242246
let iter = platform.prefixed(&prefix).ok()?;
243247
let prefix = prefix.to_str()?;

gix/src/remote/connection/fetch/receive_pack.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ where
7878
P: Progress,
7979
P::SubProgress: 'static,
8080
{
81+
let _span = gix_trace::coarse!("fetch::Prepare::receive()");
8182
let mut con = self.con.take().expect("receive() can only be called once");
8283

8384
let handshake = &self.ref_map.handshake;
@@ -115,6 +116,7 @@ where
115116
});
116117
}
117118

119+
let negotiate_span = gix_trace::detail!("negotiate");
118120
let mut negotiator = repo
119121
.config
120122
.resolved
@@ -217,6 +219,8 @@ where
217219
};
218220
let graph = graph.detach();
219221
drop(graph_repo);
222+
drop(negotiate_span);
223+
220224
let previous_response = previous_response.expect("knowledge of a pack means a response was received");
221225
if !previous_response.shallow_updates().is_empty() && shallow_lock.is_none() {
222226
let reject_shallow_remote = repo

gix/src/remote/connection/fetch/update_refs/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub(crate) fn update(
5353
dry_run: fetch::DryRun,
5454
write_packed_refs: fetch::WritePackedRefs,
5555
) -> Result<update::Outcome, update::Error> {
56+
let _span = gix_trace::detail!("update_refs()");
5657
let mut edits = Vec::new();
5758
let mut updates = Vec::new();
5859

0 commit comments

Comments
 (0)