Skip to content

Commit

Permalink
Add a flag to allow performance logging: GITBUTLER_PERFORMANCE_LOG
Browse files Browse the repository at this point in the history
````
GITBUTLER_PERFORMANCE_LOG=1 LOG_LEVEL=debug pnpm tauri dev
````

Additionally, some noise was removed by turning a warning into
a trace.
  • Loading branch information
Byron committed Aug 28, 2024
1 parent 7e0878a commit fc63929
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 17 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ The app writes logs into:
1. `stdout` in development mode
2. The Tauri [logs](https://tauri.app/v1/api/js/path/#platform-specific) directory

One can get performance log when launching the application locally as follows:

```bash
GITBUTLER_PERFORMANCE_LOG=1 LOG_LEVEL=debug pnpm tauri dev
```

### Tokio

We are also collecting tokio's runtime tracing information that could be viewed using [tokio-console](https://github.com/tokio-rs/console#tokio-console-prototypes):
Expand Down
11 changes: 8 additions & 3 deletions crates/gitbutler-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,19 @@ fn main() -> Result<()> {
}

mod trace {
use tracing::metadata::LevelFilter;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::Layer;

pub fn init() -> anyhow::Result<()> {
tracing_subscriber::registry()
.with(tracing_forest::ForestLayer::from(
tracing_forest::printer::PrettyPrinter::new().writer(std::io::stderr),
))
.with(
tracing_forest::ForestLayer::from(
tracing_forest::printer::PrettyPrinter::new().writer(std::io::stderr),
)
.with_filter(LevelFilter::DEBUG),
)
.init();
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/gitbutler-command-context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl CommandContext {
Ok(false) => true,
Ok(true) => false,
Err(err) => {
tracing::warn!(
tracing::trace!(
"failed to get gitbutler.didSetPrune for repository at {}; cannot disable gc: {}",
project.path.display(),
err
Expand Down
1 change: 1 addition & 0 deletions crates/gitbutler-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ tokio = { workspace = true, features = ["rt-multi-thread", "parking_lot"] }
tracing.workspace = true
tracing-appender = "0.2.3"
tracing-subscriber.workspace = true
tracing-forest = { version = "0.1.6" }
gitbutler-watcher.workspace = true
gitbutler-branch-actions.workspace = true
gitbutler-oplog.workspace = true
Expand Down
36 changes: 24 additions & 12 deletions crates/gitbutler-tauri/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tracing::{instrument, metadata::LevelFilter, subscriber::set_global_default}
use tracing_appender::rolling::{RollingFileAppender, Rotation};
use tracing_subscriber::{fmt::format::FmtSpan, layer::SubscriberExt, Layer};

pub fn init(app_handle: &AppHandle) {
pub fn init(app_handle: &AppHandle, performance_logging: bool) {
let logs_dir = app_handle
.path_resolver()
.app_log_dir()
Expand Down Expand Up @@ -53,25 +53,37 @@ pub fn init(app_handle: &AppHandle) {
.recording_path(logs_dir.join("tokio-console"))
.spawn(),
)
.with(
// subscriber that writes spans to stdout
tracing_subscriber::fmt::layer()
.event_format(format_for_humans.clone())
.with_ansi(use_colors_in_logs)
.with_span_events(FmtSpan::CLOSE)
.with_filter(log_level_filter),
)
.with(
// subscriber that writes spans to a file
tracing_subscriber::fmt::layer()
.event_format(format_for_humans)
.event_format(format_for_humans.clone())
.with_ansi(false)
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
.with_writer(file_writer)
.with_filter(log_level_filter),
);

set_global_default(subscriber).expect("failed to set subscriber");
if performance_logging {
set_global_default(
subscriber.with(
tracing_forest::ForestLayer::from(
tracing_forest::printer::PrettyPrinter::new().writer(std::io::stdout),
)
.with_filter(log_level_filter),
),
)
} else {
set_global_default(
subscriber.with(
// subscriber that writes spans to stdout
tracing_subscriber::fmt::layer()
.event_format(format_for_humans)
.with_ansi(use_colors_in_logs)
.with_span_events(FmtSpan::CLOSE)
.with_filter(log_level_filter),
),
)
}
.expect("failed to set subscriber");
}

fn get_server_addr(app_handle: &AppHandle) -> (Ipv4Addr, u16) {
Expand Down
3 changes: 2 additions & 1 deletion crates/gitbutler-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use tauri::{generate_context, Manager};
use tauri_plugin_log::LogTarget;

fn main() {
let performance_logging = std::env::var_os("GITBUTLER_PERFORMANCE_LOG").is_some();
gitbutler_project::configure_git2();
let tauri_context = generate_context!();
gitbutler_secret::secret::set_application_namespace(
Expand Down Expand Up @@ -60,7 +61,7 @@ fn main() {

let app_handle = tauri_app.handle();

logs::init(&app_handle);
logs::init(&app_handle, performance_logging);

// On MacOS, in dev mode with debug assertions, we encounter popups each time
// the binary is rebuilt. To counter that, use a git-credential based implementation.
Expand Down

0 comments on commit fc63929

Please sign in to comment.