Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed May 28, 2024
1 parent 6015c64 commit f3c68cb
Show file tree
Hide file tree
Showing 16 changed files with 924 additions and 899 deletions.
23 changes: 19 additions & 4 deletions tokio/src/macros/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ macro_rules! cfg_macros {
}
}

// See https://github.com/tokio-rs/tokio/issues/6546, https://github.com/tokio-rs/tokio/issues/4073
macro_rules! cfg_unstable_metrics {
($($item:item)*) => {
$(
Expand All @@ -235,9 +234,13 @@ macro_rules! cfg_not_unstable_metrics {
}
}

// Swap in mock metrics when loom is active
macro_rules! cfg_not_metrics {
($($item:item)*) => {};
macro_rules! cfg_not_unstable_metrics {
($($item:item)*) => {
$(
#[cfg(not(tokio_unstable))]
$item
)*
}
}

macro_rules! cfg_not_rt_and_metrics_and_net {
Expand All @@ -246,6 +249,18 @@ macro_rules! cfg_not_rt_and_metrics_and_net {
};
}

macro_rules! cfg_net_and_unstable {
($($item:item)*) => {
$(
#[cfg(tokio_unstable)]
#[cfg_attr(docsrs, doc(cfg(tokio_unstable)))]
#[cfg(feature = "net")]
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
$item
)*
};
}

macro_rules! cfg_net_or_process {
($($item:item)*) => {
$(
Expand Down
1 change: 1 addition & 0 deletions tokio/src/runtime/blocking/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl SpawnerMetrics {
self.num_idle_threads.load(Ordering::Relaxed)
}

// TODO(rcoh): why is this gated?
cfg_unstable_metrics! {
fn queue_depth(&self) -> usize {
self.queue_depth.load(Ordering::Relaxed)
Expand Down
17 changes: 2 additions & 15 deletions tokio/src/runtime/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use std::future::Future;
use std::marker::PhantomData;
use std::{error, fmt};

use super::RuntimeMetrics;

/// Runtime context guard.
///
/// Returned by [`Runtime::enter`] and [`Handle::enter`], the context guard exits
Expand Down Expand Up @@ -393,24 +395,9 @@ impl Handle {
owned_id.into()
}
}
}

use crate::runtime::RuntimeMetrics;

impl Handle {
/// Returns a view that lets you get information about how the runtime
/// is performing.
///
/// # Examples
/// ```
/// use tokio::runtime::Handle;
///
/// #[tokio::main]
/// async fn main() {
/// let metrics = Handle::current().metrics();
/// println!("The runtime has {} workers", metrics.num_workers());
/// }
/// ```
pub fn metrics(&self) -> RuntimeMetrics {
RuntimeMetrics::new(self.clone())
}
Expand Down
3 changes: 2 additions & 1 deletion tokio/src/runtime/metrics/histogram.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::sync::atomic::{AtomicU64, 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::{AtomicU64, Ordering::Relaxed};
use crate::util::metric_atomics::MetricAtomicU64;
use std::sync::atomic::Ordering::Relaxed;

#[derive(Default)]
pub(crate) struct IoDriverMetrics {
Expand Down
4 changes: 3 additions & 1 deletion tokio/src/runtime/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ mod runtime;
pub use runtime::RuntimeMetrics;

cfg_unstable_metrics! {

mod batch;
pub(crate) use batch::MetricsBatch;

cfg_unstable_metrics! {


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

Expand Down
Loading

0 comments on commit f3c68cb

Please sign in to comment.