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.
This commit is contained in:
Sebastian Thiel 2024-08-28 11:19:17 +02:00
parent 7e0878a14f
commit fc63929da3
No known key found for this signature in database
GPG Key ID: 9CB5EE7895E8268B
7 changed files with 43 additions and 17 deletions

1
Cargo.lock generated
View File

@ -2565,6 +2565,7 @@ dependencies = [
"tokio", "tokio",
"tracing", "tracing",
"tracing-appender", "tracing-appender",
"tracing-forest",
"tracing-subscriber", "tracing-subscriber",
] ]

View File

@ -132,6 +132,12 @@ The app writes logs into:
1. `stdout` in development mode 1. `stdout` in development mode
2. The Tauri [logs](https://tauri.app/v1/api/js/path/#platform-specific) directory 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 ### 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): 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):

View File

@ -77,14 +77,19 @@ fn main() -> Result<()> {
} }
mod trace { mod trace {
use tracing::metadata::LevelFilter;
use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::Layer;
pub fn init() -> anyhow::Result<()> { pub fn init() -> anyhow::Result<()> {
tracing_subscriber::registry() tracing_subscriber::registry()
.with(tracing_forest::ForestLayer::from( .with(
tracing_forest::printer::PrettyPrinter::new().writer(std::io::stderr), tracing_forest::ForestLayer::from(
)) tracing_forest::printer::PrettyPrinter::new().writer(std::io::stderr),
)
.with_filter(LevelFilter::DEBUG),
)
.init(); .init();
Ok(()) Ok(())
} }

View File

@ -28,7 +28,7 @@ impl CommandContext {
Ok(false) => true, Ok(false) => true,
Ok(true) => false, Ok(true) => false,
Err(err) => { Err(err) => {
tracing::warn!( tracing::trace!(
"failed to get gitbutler.didSetPrune for repository at {}; cannot disable gc: {}", "failed to get gitbutler.didSetPrune for repository at {}; cannot disable gc: {}",
project.path.display(), project.path.display(),
err err

View File

@ -47,6 +47,7 @@ tokio = { workspace = true, features = ["rt-multi-thread", "parking_lot"] }
tracing.workspace = true tracing.workspace = true
tracing-appender = "0.2.3" tracing-appender = "0.2.3"
tracing-subscriber.workspace = true tracing-subscriber.workspace = true
tracing-forest = { version = "0.1.6" }
gitbutler-watcher.workspace = true gitbutler-watcher.workspace = true
gitbutler-branch-actions.workspace = true gitbutler-branch-actions.workspace = true
gitbutler-oplog.workspace = true gitbutler-oplog.workspace = true

View File

@ -5,7 +5,7 @@ use tracing::{instrument, metadata::LevelFilter, subscriber::set_global_default}
use tracing_appender::rolling::{RollingFileAppender, Rotation}; use tracing_appender::rolling::{RollingFileAppender, Rotation};
use tracing_subscriber::{fmt::format::FmtSpan, layer::SubscriberExt, Layer}; 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 let logs_dir = app_handle
.path_resolver() .path_resolver()
.app_log_dir() .app_log_dir()
@ -53,25 +53,37 @@ pub fn init(app_handle: &AppHandle) {
.recording_path(logs_dir.join("tokio-console")) .recording_path(logs_dir.join("tokio-console"))
.spawn(), .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( .with(
// subscriber that writes spans to a file // subscriber that writes spans to a file
tracing_subscriber::fmt::layer() tracing_subscriber::fmt::layer()
.event_format(format_for_humans) .event_format(format_for_humans.clone())
.with_ansi(false) .with_ansi(false)
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE) .with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
.with_writer(file_writer) .with_writer(file_writer)
.with_filter(log_level_filter), .with_filter(log_level_filter),
); );
if performance_logging {
set_global_default(subscriber).expect("failed to set subscriber"); 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) { fn get_server_addr(app_handle: &AppHandle) -> (Ipv4Addr, u16) {

View File

@ -20,6 +20,7 @@ use tauri::{generate_context, Manager};
use tauri_plugin_log::LogTarget; use tauri_plugin_log::LogTarget;
fn main() { fn main() {
let performance_logging = std::env::var_os("GITBUTLER_PERFORMANCE_LOG").is_some();
gitbutler_project::configure_git2(); gitbutler_project::configure_git2();
let tauri_context = generate_context!(); let tauri_context = generate_context!();
gitbutler_secret::secret::set_application_namespace( gitbutler_secret::secret::set_application_namespace(
@ -60,7 +61,7 @@ fn main() {
let app_handle = tauri_app.handle(); 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 // 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. // the binary is rebuilt. To counter that, use a git-credential based implementation.