Skip to content

Commit

Permalink
rt: add io_driver_ready_count metric
Browse files Browse the repository at this point in the history
This change also adds a new default feature, `net`.
  • Loading branch information
Noah-Kennedy committed Mar 3, 2023
1 parent 3ece4ff commit 2d8dfef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ categories = ["asynchronous", "network-programming"]
keywords = ["async", "futures", "metrics", "debugging"]

[features]
default = ["rt"]
default = ["rt", "net"]
rt = ["tokio"]
net = ["tokio/net"]

[dependencies]
tokio-stream = "0.1.11"
Expand Down
11 changes: 11 additions & 0 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,12 @@ pub struct RuntimeMetrics {
/// ##### Definition
/// This metric is derived from [`tokio::runtime::RuntimeMetrics::budget_forced_yield_count`].
pub budget_forced_yield_count: u64,

/// Returns the number of ready events processed by the runtime’s I/O driver.
///
/// ##### Definition
/// This metric is derived from [`tokio::runtime::RuntimeMetrics::io_driver_ready_count`].
pub io_driver_ready_count: u64,
}

/// Snapshot of per-worker metrics
Expand Down Expand Up @@ -971,6 +977,7 @@ pub struct RuntimeIntervals {
// Number of tasks scheduled from *outside* of the runtime
num_remote_schedules: u64,
budget_forced_yield_count: u64,
io_driver_ready_count: u64,
}

impl RuntimeIntervals {
Expand All @@ -979,6 +986,7 @@ impl RuntimeIntervals {

let num_remote_schedules = self.runtime.remote_schedule_count();
let budget_forced_yields = self.runtime.budget_forced_yield_count();
let io_driver_ready_events = self.runtime.io_driver_ready_count();

let mut metrics = RuntimeMetrics {
workers_count: self.runtime.num_workers(),
Expand All @@ -994,12 +1002,14 @@ impl RuntimeIntervals {
min_busy_duration: Duration::from_secs(1000000000),
min_local_queue_depth: usize::MAX,
budget_forced_yield_count: budget_forced_yields - self.budget_forced_yield_count,
io_driver_ready_count: io_driver_ready_events - self.io_driver_ready_count,
..Default::default()
};

self.num_remote_schedules = num_remote_schedules;
self.started_at = now;
self.budget_forced_yield_count = budget_forced_yields;
self.io_driver_ready_count = io_driver_ready_events;

for worker in &mut self.workers {
worker.probe(&self.runtime, &mut metrics);
Expand Down Expand Up @@ -1084,6 +1094,7 @@ impl RuntimeMonitor {
workers,
num_remote_schedules: self.runtime.remote_schedule_count(),
budget_forced_yield_count: self.runtime.budget_forced_yield_count(),
io_driver_ready_count: self.runtime.io_driver_ready_count(),
}
}
}
Expand Down

0 comments on commit 2d8dfef

Please sign in to comment.