Skip to content

Commit

Permalink
metrics: stabilize RuntimeMetrics::worker_count
Browse files Browse the repository at this point in the history
This PR stabilizes a single metric API to start the process of stabilizing metrics.
Future work will continue to stabilize more metrics.

Refs: tokio-rs#6546
  • Loading branch information
rcoh committed May 14, 2024
1 parent 6fcd9c0 commit 1df9b3d
Show file tree
Hide file tree
Showing 18 changed files with 955 additions and 933 deletions.
1 change: 1 addition & 0 deletions tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ compile_error!("The `tokio_taskdump` feature requires `--cfg tokio_unstable`.");

#[cfg(all(
tokio_taskdump,
not(doc),
not(all(
target_os = "linux",
any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")
Expand Down
14 changes: 11 additions & 3 deletions tokio/src/macros/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,19 @@ macro_rules! cfg_macros {
}
}

// need to disable metrics on loom
macro_rules! cfg_metrics {
($($item:item)*) => {
$(
// For now, metrics is only disabled in loom tests.
// When stabilized, it might have a dedicated feature flag.
#[cfg(not(loom))]
$item
)*
}
}

macro_rules! cfg_unstable_metrics {
($($item:item)*) => {
$(
#[cfg(all(tokio_unstable, not(loom)))]
#[cfg_attr(docsrs, doc(cfg(tokio_unstable)))]
$item
Expand All @@ -230,7 +238,7 @@ macro_rules! cfg_metrics {
macro_rules! cfg_not_metrics {
($($item:item)*) => {
$(
#[cfg(not(all(tokio_unstable, not(loom))))]
#[cfg(not(all(not(loom))))]
$item
)*
}
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/runtime/blocking/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl SpawnerMetrics {
self.num_idle_threads.load(Ordering::Relaxed)
}

cfg_metrics! {
cfg_unstable_metrics! {
fn queue_depth(&self) -> usize {
self.queue_depth.load(Ordering::Relaxed)
}
Expand Down Expand Up @@ -474,7 +474,7 @@ impl Spawner {
}
}

cfg_metrics! {
cfg_unstable_metrics! {
impl Spawner {
pub(crate) fn num_threads(&self) -> usize {
self.inner.metrics.num_threads()
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/runtime/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ impl Builder {
}
}

cfg_metrics! {
cfg_unstable_metrics! {
/// Enables tracking the distribution of task poll times.
///
/// Task poll times are not instrumented by default as doing so requires
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/runtime/coop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ cfg_coop! {
}

cfg_rt! {
cfg_metrics! {
cfg_unstable_metrics! {
#[inline(always)]
fn inc_budget_forced_yield_count() {
let _ = context::with_current(|handle| {
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/runtime/io/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cfg_not_rt_and_metrics_and_net! {

cfg_net! {
cfg_rt! {
cfg_metrics! {
cfg_unstable_metrics! {
pub(crate) use crate::runtime::IoDriverMetrics;
}
}
Expand Down
33 changes: 17 additions & 16 deletions tokio/src/runtime/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@
#![allow(clippy::module_inception)]

cfg_metrics! {
mod batch;
pub(crate) use batch::MetricsBatch;

mod histogram;
pub(crate) use histogram::{Histogram, HistogramBatch, HistogramBuilder};
#[allow(unreachable_pub)] // rust-lang/rust#57411
pub use histogram::HistogramScale;

mod runtime;
#[allow(unreachable_pub)] // rust-lang/rust#57411
pub use runtime::RuntimeMetrics;

mod scheduler;
pub(crate) use scheduler::SchedulerMetrics;
cfg_unstable_metrics! {
mod batch;
pub(crate) use batch::MetricsBatch;

mod histogram;
pub(crate) use histogram::{Histogram, HistogramBatch, HistogramBuilder};
#[allow(unreachable_pub)] // rust-lang/rust#57411
pub use histogram::HistogramScale;

mod scheduler;
pub(crate) use scheduler::SchedulerMetrics;

mod worker;
pub(crate) use worker::WorkerMetrics;
mod worker;
pub(crate) use worker::WorkerMetrics;

cfg_net! {
mod io;
pub(crate) use io::IoDriverMetrics;
cfg_net! {
mod io;
pub(crate) use io::IoDriverMetrics;
}
}
}

Expand Down
Loading

0 comments on commit 1df9b3d

Please sign in to comment.