diff --git a/tests-integration/Cargo.toml b/tests-integration/Cargo.toml index 5ab8c15db3d..a45c4deac0d 100644 --- a/tests-integration/Cargo.toml +++ b/tests-integration/Cargo.toml @@ -20,7 +20,7 @@ required-features = ["rt-process-signal"] # For mem check rt-net = ["tokio/rt", "tokio/rt-multi-thread", "tokio/net"] # For test-process-signal -rt-process-signal = ["rt", "tokio/process", "tokio/signal"] +rt-process-signal = ["rt-net", "tokio/process", "tokio/signal"] full = [ "macros", diff --git a/tokio/src/runtime/metrics/mod.rs b/tokio/src/runtime/metrics/mod.rs index effc7c64a45..4b96f1b7115 100644 --- a/tokio/src/runtime/metrics/mod.rs +++ b/tokio/src/runtime/metrics/mod.rs @@ -22,8 +22,10 @@ cfg_metrics! { mod worker; pub(crate) use worker::WorkerMetrics; - mod io; - pub(crate) use io::IoDriverMetrics; + cfg_net! { + mod io; + pub(crate) use io::IoDriverMetrics; + } } cfg_not_metrics! { diff --git a/tokio/src/runtime/metrics/runtime.rs b/tokio/src/runtime/metrics/runtime.rs index 653f4b411b6..2183beda42a 100644 --- a/tokio/src/runtime/metrics/runtime.rs +++ b/tokio/src/runtime/metrics/runtime.rs @@ -3,8 +3,6 @@ use crate::runtime::Handle; use std::sync::atomic::Ordering::Relaxed; use std::time::Duration; -use super::IoDriverMetrics; - /// Handle to the runtime's metrics. /// /// This handle is internally reference-counted and can be freely cloned. A @@ -448,58 +446,62 @@ impl RuntimeMetrics { pub fn worker_local_queue_depth(&self, worker: usize) -> usize { self.handle.spawner.worker_local_queue_depth(worker) } +} - /// Returns the number of file descriptors currently registered with the - /// runtime's I/O driver. - /// - /// # Examples - /// - /// ``` - /// use tokio::runtime::Handle; - /// - /// #[tokio::main] - /// async fn main() { - /// let metrics = Handle::current().metrics(); - /// - /// let n = metrics.io_driver_fd_count(); - /// println!("{} fds currently registered with the runtime's I/O driver.", n); - /// } - /// ``` - pub fn io_driver_fd_count(&self) -> u64 { - self.with_io_driver_metrics(|m| m.fd_count.load(Relaxed)) - } +cfg_net! { + impl RuntimeMetrics { + /// Returns the number of file descriptors currently registered with the + /// runtime's I/O driver. + /// + /// # Examples + /// + /// ``` + /// use tokio::runtime::Handle; + /// + /// #[tokio::main] + /// async fn main() { + /// let metrics = Handle::current().metrics(); + /// + /// let n = metrics.io_driver_fd_count(); + /// println!("{} fds currently registered with the runtime's I/O driver.", n); + /// } + /// ``` + pub fn io_driver_fd_count(&self) -> u64 { + self.with_io_driver_metrics(|m| m.fd_count.load(Relaxed)) + } - /// Returns the number of ready events processed by the runtime's - /// I/O driver. - /// - /// # Examples - /// - /// ``` - /// use tokio::runtime::Handle; - /// - /// #[tokio::main] - /// async fn main() { - /// let metrics = Handle::current().metrics(); - /// - /// let n = metrics.io_driver_ready_count(); - /// println!("{} ready events procssed by the runtime's I/O driver.", n); - /// } - /// ``` - pub fn io_driver_ready_count(&self) -> u64 { - self.with_io_driver_metrics(|m| m.ready_count.load(Relaxed)) - } + /// Returns the number of ready events processed by the runtime's + /// I/O driver. + /// + /// # Examples + /// + /// ``` + /// use tokio::runtime::Handle; + /// + /// #[tokio::main] + /// async fn main() { + /// let metrics = Handle::current().metrics(); + /// + /// let n = metrics.io_driver_ready_count(); + /// println!("{} ready events procssed by the runtime's I/O driver.", n); + /// } + /// ``` + pub fn io_driver_ready_count(&self) -> u64 { + self.with_io_driver_metrics(|m| m.ready_count.load(Relaxed)) + } - fn with_io_driver_metrics(&self, f: F) -> u64 - where - F: Fn(&IoDriverMetrics) -> u64, - { - // TODO: Investigate if this should return 0, most of our metrics always increase - // thus this breaks that guarantee. - self.handle - .io_handle - .as_ref() - .map(|h| h.with_io_driver_metrics(f)) - .flatten() - .unwrap_or(0) + fn with_io_driver_metrics(&self, f: F) -> u64 + where + F: Fn(&super::IoDriverMetrics) -> u64, + { + // TODO: Investigate if this should return 0, most of our metrics always increase + // thus this breaks that guarantee. + self.handle + .io_handle + .as_ref() + .map(|h| h.with_io_driver_metrics(f)) + .flatten() + .unwrap_or(0) + } } } diff --git a/tokio/src/runtime/mod.rs b/tokio/src/runtime/mod.rs index dad07e2bb00..66856df66c7 100644 --- a/tokio/src/runtime/mod.rs +++ b/tokio/src/runtime/mod.rs @@ -186,7 +186,11 @@ cfg_metrics! { mod metrics; pub use metrics::RuntimeMetrics; - pub(crate) use metrics::{MetricsBatch, SchedulerMetrics, WorkerMetrics, IoDriverMetrics}; + pub(crate) use metrics::{MetricsBatch, SchedulerMetrics, WorkerMetrics}; + + cfg_net! { + pub(crate) use metrics::IoDriverMetrics; + } } cfg_not_metrics! {