Skip to content

Commit fc63929

Browse files
committed
Add a flag to allow performance logging: GITBUTLER_PERFORMANCE_LOG
```` GITBUTLER_PERFORMANCE_LOG=1 LOG_LEVEL=debug pnpm tauri dev ```` Additionally, some noise was removed by turning a warning into a trace.
1 parent 7e0878a commit fc63929

File tree

7 files changed

+43
-17
lines changed

7 files changed

+43
-17
lines changed

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.

DEVELOPMENT.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ The app writes logs into:
132132
1. `stdout` in development mode
133133
2. The Tauri [logs](https://tauri.app/v1/api/js/path/#platform-specific) directory
134134

135+
One can get performance log when launching the application locally as follows:
136+
137+
```bash
138+
GITBUTLER_PERFORMANCE_LOG=1 LOG_LEVEL=debug pnpm tauri dev
139+
```
140+
135141
### Tokio
136142

137143
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):

crates/gitbutler-cli/src/main.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,19 @@ fn main() -> Result<()> {
7777
}
7878

7979
mod trace {
80+
use tracing::metadata::LevelFilter;
8081
use tracing_subscriber::layer::SubscriberExt;
8182
use tracing_subscriber::util::SubscriberInitExt;
83+
use tracing_subscriber::Layer;
8284

8385
pub fn init() -> anyhow::Result<()> {
8486
tracing_subscriber::registry()
85-
.with(tracing_forest::ForestLayer::from(
86-
tracing_forest::printer::PrettyPrinter::new().writer(std::io::stderr),
87-
))
87+
.with(
88+
tracing_forest::ForestLayer::from(
89+
tracing_forest::printer::PrettyPrinter::new().writer(std::io::stderr),
90+
)
91+
.with_filter(LevelFilter::DEBUG),
92+
)
8893
.init();
8994
Ok(())
9095
}

crates/gitbutler-command-context/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl CommandContext {
2828
Ok(false) => true,
2929
Ok(true) => false,
3030
Err(err) => {
31-
tracing::warn!(
31+
tracing::trace!(
3232
"failed to get gitbutler.didSetPrune for repository at {}; cannot disable gc: {}",
3333
project.path.display(),
3434
err

crates/gitbutler-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ tokio = { workspace = true, features = ["rt-multi-thread", "parking_lot"] }
4747
tracing.workspace = true
4848
tracing-appender = "0.2.3"
4949
tracing-subscriber.workspace = true
50+
tracing-forest = { version = "0.1.6" }
5051
gitbutler-watcher.workspace = true
5152
gitbutler-branch-actions.workspace = true
5253
gitbutler-oplog.workspace = true

crates/gitbutler-tauri/src/logs.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use tracing::{instrument, metadata::LevelFilter, subscriber::set_global_default}
55
use tracing_appender::rolling::{RollingFileAppender, Rotation};
66
use tracing_subscriber::{fmt::format::FmtSpan, layer::SubscriberExt, Layer};
77

8-
pub fn init(app_handle: &AppHandle) {
8+
pub fn init(app_handle: &AppHandle, performance_logging: bool) {
99
let logs_dir = app_handle
1010
.path_resolver()
1111
.app_log_dir()
@@ -53,25 +53,37 @@ pub fn init(app_handle: &AppHandle) {
5353
.recording_path(logs_dir.join("tokio-console"))
5454
.spawn(),
5555
)
56-
.with(
57-
// subscriber that writes spans to stdout
58-
tracing_subscriber::fmt::layer()
59-
.event_format(format_for_humans.clone())
60-
.with_ansi(use_colors_in_logs)
61-
.with_span_events(FmtSpan::CLOSE)
62-
.with_filter(log_level_filter),
63-
)
6456
.with(
6557
// subscriber that writes spans to a file
6658
tracing_subscriber::fmt::layer()
67-
.event_format(format_for_humans)
59+
.event_format(format_for_humans.clone())
6860
.with_ansi(false)
6961
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
7062
.with_writer(file_writer)
7163
.with_filter(log_level_filter),
7264
);
73-
74-
set_global_default(subscriber).expect("failed to set subscriber");
65+
if performance_logging {
66+
set_global_default(
67+
subscriber.with(
68+
tracing_forest::ForestLayer::from(
69+
tracing_forest::printer::PrettyPrinter::new().writer(std::io::stdout),
70+
)
71+
.with_filter(log_level_filter),
72+
),
73+
)
74+
} else {
75+
set_global_default(
76+
subscriber.with(
77+
// subscriber that writes spans to stdout
78+
tracing_subscriber::fmt::layer()
79+
.event_format(format_for_humans)
80+
.with_ansi(use_colors_in_logs)
81+
.with_span_events(FmtSpan::CLOSE)
82+
.with_filter(log_level_filter),
83+
),
84+
)
85+
}
86+
.expect("failed to set subscriber");
7587
}
7688

7789
fn get_server_addr(app_handle: &AppHandle) -> (Ipv4Addr, u16) {

crates/gitbutler-tauri/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use tauri::{generate_context, Manager};
2020
use tauri_plugin_log::LogTarget;
2121

2222
fn main() {
23+
let performance_logging = std::env::var_os("GITBUTLER_PERFORMANCE_LOG").is_some();
2324
gitbutler_project::configure_git2();
2425
let tauri_context = generate_context!();
2526
gitbutler_secret::secret::set_application_namespace(
@@ -60,7 +61,7 @@ fn main() {
6061

6162
let app_handle = tauri_app.handle();
6263

63-
logs::init(&app_handle);
64+
logs::init(&app_handle, performance_logging);
6465

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

0 commit comments

Comments
 (0)