Skip to content

Commit

Permalink
fix more feature flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucio Franco committed Feb 17, 2022
1 parent e7dc9d5 commit b3d5df7
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 56 deletions.
2 changes: 1 addition & 1 deletion tests-integration/Cargo.toml
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions tokio/src/runtime/metrics/mod.rs
Expand Up @@ -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! {
Expand Down
106 changes: 54 additions & 52 deletions tokio/src/runtime/metrics/runtime.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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<F>(&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<F>(&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)
}
}
}
6 changes: 5 additions & 1 deletion tokio/src/runtime/mod.rs
Expand Up @@ -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! {
Expand Down

0 comments on commit b3d5df7

Please sign in to comment.