add --trace to enable tracing

This is useful to get simple performance metrics.
This commit is contained in:
Sebastian Thiel 2024-08-11 14:55:00 +02:00
parent 77cbc50a68
commit 96e0d3e83f
No known key found for this signature in database
GPG Key ID: 9CB5EE7895E8268B
16 changed files with 41 additions and 14 deletions

View File

@ -52,6 +52,8 @@ fslock = "0.2.1"
parking_lot = "0.12.3"
futures = "0.3.30"
toml = "0.8.13"
tracing = "0.1.40"
tracing-subscriber = "0.3.17"
gitbutler-id = { path = "crates/gitbutler-id" }
gitbutler-git = { path = "crates/gitbutler-git" }

View File

@ -6,7 +6,7 @@ authors = ["GitButler <gitbutler@gitbutler.com>"]
publish = false
[dependencies]
tracing = "0.1.40"
tracing.workspace = true
anyhow = "1.0.86"
git2.workspace = true
gix.workspace = true

View File

@ -21,7 +21,7 @@ serde = { workspace = true, features = ["std"] }
bstr.workspace = true
md5 = "0.7.0"
hex = "0.4.3"
tracing = "0.1.40"
tracing.workspace = true
lazy_static = "1.4.0"
[[test]]

View File

@ -18,8 +18,11 @@ gitbutler-branch-actions.workspace = true
gitbutler-command-context.workspace = true
gitbutler-branch.workspace = true
gitbutler-diff.workspace = true
gix = { workspace = true, features = ["max-performance-safe"] }
gix = { workspace = true, features = ["max-performance-safe", "tracing"] }
dirs-next = "2.0.0"
clap = { version = "4.5.13", features = ["derive", "env"] }
anyhow = "1.0.86"
chrono = "0.4.10"
tracing-forest = { version = "0.1.6" }
tracing-subscriber.workspace = true
tracing.workspace = true

View File

@ -3,6 +3,9 @@ use std::path::PathBuf;
#[derive(Debug, clap::Parser)]
#[clap(name = "gitbutler-cli", about = "A CLI for GitButler", version = option_env!("GIX_VERSION"))]
pub struct Args {
/// Enable tracing for debug and performance information printed to stderr.
#[clap(short = 'd', long)]
pub trace: bool,
/// Run as if gitbutler-cli was started in PATH instead of the current working directory.
#[clap(short = 'C', long, default_value = ".", value_name = "PATH")]
pub current_dir: PathBuf,

View File

@ -11,6 +11,11 @@ fn main() -> Result<()> {
let args: Args = clap::Parser::parse();
gitbutler_project::configure_git2();
if args.trace {
trace::init()?;
}
let _op_span = tracing::info_span!("cli-op").entered();
match args.cmd {
args::Subcommands::Branch(vbranch::Platform { cmd }) => {
let project = command::prepare::project_from_path(args.current_dir)?;
@ -65,3 +70,17 @@ fn main() -> Result<()> {
}
}
}
mod trace {
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
pub fn init() -> anyhow::Result<()> {
tracing_subscriber::registry()
.with(tracing_forest::ForestLayer::from(
tracing_forest::printer::PrettyPrinter::new().writer(std::io::stderr),
))
.init();
Ok(())
}
}

View File

@ -8,6 +8,6 @@ publish = false
[dependencies]
anyhow = "1.0.86"
git2.workspace = true
tracing = "0.1.40"
tracing.workspace = true
gitbutler-project.workspace = true
itertools = "0.13"

View File

@ -11,7 +11,7 @@ bstr.workspace = true
md5 = "0.7.0"
anyhow = "1.0.86"
hex = "0.4.3"
tracing = "0.1.40"
tracing.workspace = true
gitbutler-serde.workspace = true
gitbutler-command-context.workspace = true
diffy = "0.4.0"

View File

@ -12,7 +12,7 @@ gitbutler-repo.workspace = true
serde = { workspace = true, features = ["std"] }
itertools = "0.13"
strum = { version = "0.26", features = ["derive"] }
tracing = "0.1.40"
tracing.workspace = true
gix = { workspace = true, features = ["dirwalk", "credentials", "parallel"] }
toml.workspace = true
gitbutler-project.workspace = true

View File

@ -17,7 +17,7 @@ gitbutler-storage.workspace = true
git2.workspace = true
gix = { workspace = true, features = ["dirwalk", "credentials", "parallel"] }
uuid.workspace = true
tracing = "0.1.40"
tracing.workspace = true
resolve-path = "0.1.0"
# for locking

View File

@ -12,7 +12,7 @@ anyhow = "1.0.86"
bstr.workspace = true
tokio = { workspace = true, features = [ "rt-multi-thread", "rt", "macros", "sync" ] }
gitbutler-git.workspace = true
tracing = "0.1.40"
tracing.workspace = true
tempfile = "3.10"
serde = { workspace = true, features = ["std"]}
log = "^0.4"

View File

@ -7,7 +7,7 @@ publish = false
[dependencies]
anyhow = "1.0.86"
tracing = "0.1.40"
tracing.workspace = true
serde = { workspace = true, features = ["std"]}
gix = { workspace = true, features = ["dirwalk", "credentials", "parallel"] }
keyring.workspace = true

View File

@ -7,7 +7,7 @@ publish = false
[dependencies]
anyhow = "1.0.86"
tracing = "0.1.40"
tracing.workspace = true
itertools = "0.13"
git2.workspace = true
gitbutler-oplog.workspace = true

View File

@ -44,9 +44,9 @@ log = "^0.4"
thiserror.workspace = true
# The features here optimize for performance.
tokio = { workspace = true, features = ["rt-multi-thread", "parking_lot"] }
tracing = "0.1.40"
tracing.workspace = true
tracing-appender = "0.2.3"
tracing-subscriber = "0.3.17"
tracing-subscriber.workspace = true
gitbutler-watcher.workspace = true
gitbutler-branch-actions.workspace = true
gitbutler-oplog.workspace = true

View File

@ -16,7 +16,7 @@ thiserror.workspace = true
anyhow = "1.0.86"
tokio = { workspace = true, features = ["macros"] }
tokio-util = "0.7.11"
tracing = "0.1.40"
tracing.workspace = true
gix = { workspace = true, features = [
"excludes",
"blocking-network-client",

View File

@ -11,7 +11,7 @@ doctest = false
mock_instant = ["dep:mock_instant"]
[dependencies]
tracing = "0.1.40"
tracing.workspace = true
notify = { version = "6.0.1" }
parking_lot.workspace = true