From dbe3290f89aa0d3568bab624d944b8951f27a139 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Tue, 10 Oct 2023 11:49:50 +0000 Subject: [PATCH] WIP: tracing-flame support --- Cargo.lock | 12 ++++++++++++ libs/utils/Cargo.toml | 1 + libs/utils/src/logging.rs | 3 +++ 3 files changed, 16 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index ba8c367d53..e01275b2e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4902,6 +4902,17 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "tracing-flame" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bae117ee14789185e129aaee5d93750abe67fdc5a9a62650452bfe4e122a3a9" +dependencies = [ + "lazy_static", + "tracing", + "tracing-subscriber", +] + [[package]] name = "tracing-futures" version = "0.2.5" @@ -5158,6 +5169,7 @@ dependencies = [ "tokio-util", "tracing", "tracing-error", + "tracing-flame", "tracing-subscriber", "url", "uuid", diff --git a/libs/utils/Cargo.toml b/libs/utils/Cargo.toml index 27df0265b4..f4206e1cc2 100644 --- a/libs/utils/Cargo.toml +++ b/libs/utils/Cargo.toml @@ -48,6 +48,7 @@ const_format.workspace = true # to use tokio channels as streams, this is faster to compile than async_stream # why is it only here? no other crate should use it, streams are rarely needed. tokio-stream = { version = "0.1.14" } +tracing-flame = "0.2.0" [dev-dependencies] byteorder.workspace = true diff --git a/libs/utils/src/logging.rs b/libs/utils/src/logging.rs index 502e02dc71..105ac5860b 100644 --- a/libs/utils/src/logging.rs +++ b/libs/utils/src/logging.rs @@ -77,6 +77,8 @@ pub fn init( .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")) }; + let (flame_layer, _guard) = tracing_flame::FlameLayer::with_file("./tracing.folded").unwrap(); + // NB: the order of the with() calls does not matter. // See https://docs.rs/tracing-subscriber/0.3.16/tracing_subscriber/layer/index.html#per-layer-filtering use tracing_subscriber::prelude::*; @@ -94,6 +96,7 @@ pub fn init( log_layer.with_filter(rust_log_env_filter()) }); let r = r.with(TracingEventCountLayer(&TRACING_EVENT_COUNT).with_filter(rust_log_env_filter())); + let r = r.with(flame_layer); match tracing_error_layer_enablement { TracingErrorLayerEnablement::EnableWithRustLogFilter => r .with(tracing_error::ErrorLayer::default().with_filter(rust_log_env_filter()))