Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: add support for rt poll count histogram #48

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::ops::Range;
use std::time::{Duration, Instant};
use tokio::runtime;

Expand Down Expand Up @@ -54,7 +55,7 @@
#[cfg_attr(docsrs, doc(cfg(all(tokio_unstable, feature = "rt"))))]
/// Key runtime metrics.
#[non_exhaustive]
#[derive(Default, Debug, Clone, Copy)]
#[derive(Default, Debug, Clone)]
pub struct RuntimeMetrics {
/// The number of worker threads used by the runtime.
///
Expand Down Expand Up @@ -1039,6 +1040,8 @@
/// ##### Definition
/// This metric is derived from [`tokio::runtime::RuntimeMetrics::io_driver_ready_count`].
pub io_driver_ready_count: u64,

pub task_poll_count_histogram: Option<Box<[u64]>>,
}

/// Snapshot of per-worker metrics
Expand All @@ -1053,6 +1056,7 @@
total_overflow_count: u64,
total_polls_count: u64,
total_busy_duration: Duration,
poll_count_histogram: Option<Box<[u64]>>,
}

/// Iterator returned by [`RuntimeMonitor::intervals`].
Expand Down Expand Up @@ -1093,6 +1097,11 @@
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,
task_poll_count_histogram: if self.runtime.poll_count_histogram_enabled() {

Check failure on line 1100 in src/runtime.rs

View workflow job for this annotation

GitHub Actions / check

no method named `poll_count_histogram_enabled` found for struct `tokio::runtime::RuntimeMetrics` in the current scope
Some(vec![0; self.runtime.poll_count_histogram_num_buckets()].into_boxed_slice())

Check failure on line 1101 in src/runtime.rs

View workflow job for this annotation

GitHub Actions / check

no method named `poll_count_histogram_num_buckets` found for struct `tokio::runtime::RuntimeMetrics` in the current scope
} else {
None
},
..Default::default()
};

Expand Down Expand Up @@ -1187,10 +1196,29 @@
io_driver_ready_count: self.runtime.io_driver_ready_count(),
}
}

pub fn task_poll_count_histogram_bucket_ranges(&self) -> Option<Box<[Range<Duration>]>> {
if self.runtime.poll_count_histogram_enabled() {

Check failure on line 1201 in src/runtime.rs

View workflow job for this annotation

GitHub Actions / check

no method named `poll_count_histogram_enabled` found for struct `tokio::runtime::RuntimeMetrics` in the current scope
Some((0..self.runtime.poll_count_histogram_num_buckets()).map(|bucket| self.runtime.poll_count_histogram_bucket_range(bucket)).collect::<Vec<_>>().into_boxed_slice())

Check failure on line 1202 in src/runtime.rs

View workflow job for this annotation

GitHub Actions / check

no method named `poll_count_histogram_num_buckets` found for struct `tokio::runtime::RuntimeMetrics` in the current scope

Check failure on line 1202 in src/runtime.rs

View workflow job for this annotation

GitHub Actions / check

no method named `poll_count_histogram_bucket_range` found for struct `tokio::runtime::RuntimeMetrics` in the current scope
} else {
None
}
}
}

impl Worker {
fn new(worker: usize, rt: &runtime::RuntimeMetrics) -> Worker {
let poll_count_histogram = if rt.poll_count_histogram_enabled() {

Check failure on line 1211 in src/runtime.rs

View workflow job for this annotation

GitHub Actions / check

no method named `poll_count_histogram_enabled` found for reference `&tokio::runtime::RuntimeMetrics` in the current scope
Some(
(0..rt.poll_count_histogram_num_buckets())

Check failure on line 1213 in src/runtime.rs

View workflow job for this annotation

GitHub Actions / check

no method named `poll_count_histogram_num_buckets` found for reference `&tokio::runtime::RuntimeMetrics` in the current scope
.map(|bucket| rt.poll_count_histogram_bucket_count(worker, bucket))

Check failure on line 1214 in src/runtime.rs

View workflow job for this annotation

GitHub Actions / check

no method named `poll_count_histogram_bucket_count` found for reference `&tokio::runtime::RuntimeMetrics` in the current scope
.collect::<Vec<_>>()
.into_boxed_slice(),
)
} else {
None
};

Worker {
worker,
total_park_count: rt.worker_park_count(worker),
Expand All @@ -1201,6 +1229,7 @@
total_overflow_count: rt.worker_overflow_count(worker),
total_polls_count: rt.worker_poll_count(worker),
total_busy_duration: rt.worker_total_busy_duration(worker),
poll_count_histogram,
}
}

Expand All @@ -1223,6 +1252,16 @@
}};
}

if let Some(poll_count_histogram) = &mut self.poll_count_histogram {
for (i, bucket) in poll_count_histogram.iter_mut().enumerate() {
let val = rt.poll_count_histogram_bucket_count(self.worker, i);

Check failure on line 1257 in src/runtime.rs

View workflow job for this annotation

GitHub Actions / check

no method named `poll_count_histogram_bucket_count` found for reference `&tokio::runtime::RuntimeMetrics` in the current scope
let delta = val - *bucket;
*bucket = val;

metrics.task_poll_count_histogram.as_mut().unwrap()[i] += delta;
}
}

metric!(
total_park_count,
max_park_count,
Expand Down