Skip to content

Commit

Permalink
Enable Tokio tasks profiler (#947)
Browse files Browse the repository at this point in the history
* Enable Tokio tasks profiler

Requires `logging::setup()`, but otherwise works smoothly by running [`tokio-console`](https://github.com/tokio-rs/console) client that consumes metrics emitted by IPA benchmarks and shows per-task and combined stats

* Pull tokio/tracing off the main dependency graph
  • Loading branch information
akoshelev authored Feb 20, 2024
1 parent 36c5883 commit 860e046
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
5 changes: 5 additions & 0 deletions ipa-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ descriptive-gate = []
compact-gate = ["ipa-macros/compact-gate"]
# Enable using more than one thread for protocol execution. Most of the parallelism occurs at parallel/seq_join operations
multi-threading = ["async-scoped"]
# Enable tokio task profiling. Requires tokio_unstable flag to be passed to the compiler.
# RUSTFLAGS="--cfg tokio_unstable" cargo run ... --features="tokio-console ...".
# Note that if there are other flags enabled on your platform in .cargo/config.toml, you need to include them as well.
tokio-console = ["console-subscriber", "tokio/tracing"]

# Standalone aggregation protocol. We use IPA infra for communication
# but it has nothing to do with IPA.
Expand All @@ -88,6 +92,7 @@ bytes = "1.4"
clap = { version = "4.3.2", optional = true, features = ["derive"] }
comfy-table = { version = "7.0", optional = true }
config = "0.14"
console-subscriber = { version = "0.2", optional = true }
criterion = { version = "0.5.1", optional = true, default-features = false, features = [
"async_tokio",
"plotters",
Expand Down
54 changes: 32 additions & 22 deletions ipa-core/src/test_fixture/logging.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
use std::{str::FromStr, sync::Once};

use metrics_tracing_context::MetricsLayer;
use tracing::Level;
use tracing_subscriber::{
filter::Directive, fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter,
};
use std::sync::Once;

/// Set up logging for IPA
///
Expand All @@ -14,21 +8,37 @@ pub fn setup() {
static INIT: Once = Once::new();

INIT.call_once(|| {
let default_directive = if let Some(crate_name) = option_env!("CARGO_CRATE_NAME") {
// only print IPA crate logging by default
Directive::from_str(&format!("{crate_name}=INFO")).unwrap()
} else {
Level::INFO.into()
};
#[cfg(feature = "tokio-console")]
{
console_subscriber::init();
}

#[cfg(not(feature = "tokio-console"))]
{
use std::str::FromStr;

use metrics_tracing_context::MetricsLayer;
use tracing::Level;
use tracing_subscriber::{
filter::Directive, fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter,
};

let default_directive = if let Some(crate_name) = option_env!("CARGO_CRATE_NAME") {
// only print IPA crate logging by default
Directive::from_str(&format!("{crate_name}=INFO")).unwrap()
} else {
Level::INFO.into()
};

tracing_subscriber::registry()
.with(
EnvFilter::builder()
.with_default_directive(default_directive)
.from_env_lossy(),
)
.with(fmt::layer())
.with(MetricsLayer::new())
.init();
tracing_subscriber::registry()
.with(
EnvFilter::builder()
.with_default_directive(default_directive)
.from_env_lossy(),
)
.with(fmt::layer())
.with(MetricsLayer::new())
.init();
}
});
}

0 comments on commit 860e046

Please sign in to comment.