Skip to content

Commit

Permalink
metrics: stabilize RuntimeMetrics::worker_count (#6556)
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed May 28, 2024
1 parent 9e00b26 commit 86658bd
Show file tree
Hide file tree
Showing 24 changed files with 749 additions and 752 deletions.
4 changes: 2 additions & 2 deletions tokio/src/macros/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ macro_rules! cfg_macros {
}
}

macro_rules! cfg_metrics {
macro_rules! cfg_unstable_metrics {
($($item:item)*) => {
$(
#[cfg(tokio_unstable)]
Expand Down Expand Up @@ -245,7 +245,7 @@ macro_rules! cfg_no_64bit_metrics {
}
}

macro_rules! cfg_not_metrics {
macro_rules! cfg_not_unstable_metrics {
($($item:item)*) => {
$(
#[cfg(not(tokio_unstable))]
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 @@ -957,7 +957,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
4 changes: 2 additions & 2 deletions 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 All @@ -206,7 +206,7 @@ cfg_coop! {
}
}

cfg_not_metrics! {
cfg_not_unstable_metrics! {
#[inline(always)]
fn inc_budget_forced_yield_count() {}
}
Expand Down
16 changes: 5 additions & 11 deletions tokio/src/runtime/handle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(tokio_unstable)]
use crate::runtime;
use crate::runtime::{context, scheduler, RuntimeFlavor};
use crate::runtime::{context, scheduler, RuntimeFlavor, RuntimeMetrics};

/// Handle to the runtime.
///
Expand Down Expand Up @@ -393,17 +393,11 @@ impl Handle {
owned_id.into()
}
}
}

cfg_metrics! {
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())
}
/// 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
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
2 changes: 1 addition & 1 deletion tokio/src/runtime/metrics/histogram.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::loom::sync::atomic::Ordering::Relaxed;
use crate::util::metric_atomics::MetricAtomicU64;
use std::sync::atomic::Ordering::Relaxed;

use std::cmp;
use std::ops::Range;
Expand Down
3 changes: 2 additions & 1 deletion tokio/src/runtime/metrics/io.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![cfg_attr(not(feature = "net"), allow(dead_code))]

use crate::{loom::sync::atomic::Ordering::Relaxed, util::metric_atomics::MetricAtomicU64};
use crate::util::metric_atomics::MetricAtomicU64;
use std::sync::atomic::Ordering::Relaxed;

#[derive(Default)]
pub(crate) struct IoDriverMetrics {
Expand Down
10 changes: 5 additions & 5 deletions tokio/src/runtime/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
//! [unstable]: crate#unstable-features
#![allow(clippy::module_inception)]

cfg_metrics! {
mod runtime;
pub use runtime::RuntimeMetrics;

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

Expand All @@ -17,9 +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 All @@ -33,7 +33,7 @@ cfg_metrics! {
}
}

cfg_not_metrics! {
cfg_not_unstable_metrics! {
mod mock;

pub(crate) use mock::{SchedulerMetrics, WorkerMetrics, MetricsBatch, HistogramBuilder};
Expand Down
Loading

0 comments on commit 86658bd

Please sign in to comment.