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.

This PR also introduces a `metrics` feature.

Refs: tokio-rs#6546
  • Loading branch information
rcoh committed May 13, 2024
1 parent 6fcd9c0 commit 66ee3e6
Show file tree
Hide file tree
Showing 11 changed files with 856 additions and 835 deletions.
2 changes: 2 additions & 0 deletions tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ full = [
"io-util",
"io-std",
"macros",
"metrics",
"net",
"parking_lot",
"process",
Expand All @@ -46,6 +47,7 @@ io-util = ["bytes"]
# stdin, stdout, stderr
io-std = []
macros = ["tokio-macros"]
metrics = []
net = [
"libc",
"mio/os-poll",
Expand Down
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
11 changes: 11 additions & 0 deletions tokio/src/macros/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ macro_rules! cfg_macros {
}
}

macro_rules! cfg_stable_metrics {
($($item:item)*) => {
$(
#[cfg(not(loom))]
#[cfg(feature = "metrics")]
#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
$item
)*
}
}

macro_rules! cfg_metrics {
($($item:item)*) => {
$(
Expand Down
14 changes: 7 additions & 7 deletions tokio/src/runtime/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,15 @@ impl Handle {
}
}

cfg_metrics! {
cfg_rt! {
use crate::runtime::RuntimeMetrics;
}

impl Handle {
/// Returns a view that lets you get information about how the runtime
/// is performing.
pub fn metrics(&self) -> RuntimeMetrics {
RuntimeMetrics::new(self.clone())
}
impl Handle {
/// Returns a view that lets you get information about how the runtime
/// is performing.
pub fn metrics(&self) -> RuntimeMetrics {
RuntimeMetrics::new(self.clone())
}
}

Expand Down
7 changes: 3 additions & 4 deletions tokio/src/runtime/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
//! [unstable]: crate#unstable-features
#![allow(clippy::module_inception)]

mod runtime;
pub use runtime::RuntimeMetrics;

cfg_metrics! {
mod batch;
pub(crate) use batch::MetricsBatch;
Expand All @@ -17,10 +20,6 @@ cfg_metrics! {
#[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;

Expand Down

0 comments on commit 66ee3e6

Please sign in to comment.