Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/metrics_rs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,44 @@ macro_rules! metric_refs {
),*
$(,)?
}
stable_derived {
$(
#[doc = $derived_doc:tt]
$derived_name:ident: $derived_kind:tt <$derived_unit:ident> $derived_opts:tt
),*
$(,)?
}
unstable {
$(
#[doc = $unstable_doc:tt]
$unstable_name:ident: $unstable_kind:tt <$unstable_unit:ident> $unstable_opts:tt
),*
$(,)?
}
unstable_derived {
$(
#[doc = $unstable_derived_doc:tt]
$unstable_derived_name:ident: $unstable_derived_kind:tt <$unstable_derived_unit:ident> $unstable_derived_opts:tt
),*
$(,)?
}
}
) => {
struct $struct_name {
$(
$name: crate::metrics_rs::kind_to_type!($kind),
)*
$(
$derived_name: crate::metrics_rs::kind_to_type!($derived_kind),
)*
$(
#[cfg(tokio_unstable)]
$unstable_name: crate::metrics_rs::kind_to_type!($unstable_kind),
)*
$(
#[cfg(tokio_unstable)]
$unstable_derived_name: crate::metrics_rs::kind_to_type!($unstable_derived_kind),
)*
}

impl $struct_name {
Expand All @@ -101,14 +122,30 @@ macro_rules! metric_refs {
$(
$name: crate::metrics_rs::capture_metric_ref!(transform_fn, $name: $kind $opts),
)*
$(
$derived_name: crate::metrics_rs::capture_metric_ref!(transform_fn, $derived_name: $derived_kind $derived_opts),
)*
$(
#[cfg(tokio_unstable)]
$unstable_name: crate::metrics_rs::capture_metric_ref!(transform_fn, $unstable_name: $unstable_kind $unstable_opts),
)*
$(
#[cfg(tokio_unstable)]
$unstable_derived_name: crate::metrics_rs::capture_metric_ref!(transform_fn, $unstable_derived_name: $unstable_derived_kind $unstable_derived_opts),
)*
}
}

fn emit(&self, metrics: $metrics_name, emit_arg: $emit_arg_type) {
// Emit derived metrics before base metrics because emitting base metrics may move
// out of `$metrics`.
$(
crate::metrics_rs::MyMetricOp::op((&self.$derived_name, metrics.$derived_name()), emit_arg);
)*
$(
#[cfg(tokio_unstable)]
crate::metrics_rs::MyMetricOp::op((&self.$unstable_derived_name, metrics.$unstable_derived_name()), emit_arg);
)*
$(
crate::metrics_rs::MyMetricOp::op((&self.$name, metrics.$name), emit_arg);
)*
Expand All @@ -122,10 +159,17 @@ macro_rules! metric_refs {
$(
crate::metrics_rs::describe_metric_ref!(transform_fn, $doc, $name: $kind<$unit> $opts);
)*
$(
crate::metrics_rs::describe_metric_ref!(transform_fn, $derived_doc, $derived_name: $derived_kind<$derived_unit> $derived_opts);
)*
$(
#[cfg(tokio_unstable)]
crate::metrics_rs::describe_metric_ref!(transform_fn, $unstable_doc, $unstable_name: $unstable_kind<$unstable_unit> $unstable_opts);
)*
$(
#[cfg(tokio_unstable)]
crate::metrics_rs::describe_metric_ref!(transform_fn, $unstable_derived_doc, $unstable_derived_name: $unstable_derived_kind<$unstable_derived_unit> $unstable_derived_opts);
)*
}
}

Expand Down Expand Up @@ -205,6 +249,12 @@ impl<T> MyMetricOp<T> for (&metrics::Gauge, usize) {
}
}

impl<T> MyMetricOp<T> for (&metrics::Gauge, f64) {
fn op(self, _t: T) {
self.0.set(self.1);
}
}

#[cfg(tokio_unstable)]
impl MyMetricOp<&tokio::runtime::RuntimeMetrics> for (&metrics::Histogram, Vec<u64>) {
fn op(self, tokio: &tokio::runtime::RuntimeMetrics) {
Expand Down
8 changes: 8 additions & 0 deletions src/runtime/metrics_rs_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ metric_refs! {
/// The number of tasks currently scheduled in the runtime's global queue
global_queue_depth: Gauge<Count> [],
}
stable_derived {
/// The ratio of the [`RuntimeMetrics::total_busy_duration`] to the [`RuntimeMetrics::elapsed`].
busy_ratio: Gauge<Percent> [],
}
unstable {
/// The average duration of a single invocation of poll on a task
mean_poll_duration: Gauge<Microseconds> [],
Expand Down Expand Up @@ -330,6 +334,10 @@ metric_refs! {
/// Returns the number of ready events processed by the runtime’s I/O driver
io_driver_ready_count: Counter<Count> [],
}
unstable_derived {
/// The ratio of the [`RuntimeMetrics::total_polls_count`] to the [`RuntimeMetrics::total_noop_count`].
mean_polls_per_park: Gauge<Percent> [],
}
}
}

Expand Down
23 changes: 23 additions & 0 deletions src/task/metrics_rs_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,30 @@ metric_refs! {
/// The total number of times that a task had a long scheduling duration.
total_long_delay_duration: Counter<Microseconds> [],
}
stable_derived {
/// The mean duration elapsed between the instant tasks are instrumented, and the instant they are first polled.
mean_first_poll_delay: Counter<Microseconds> [],
/// The mean duration of idles.
mean_idle_duration: Counter<Microseconds> [],
/// The mean duration that tasks spent waiting to be executed after awakening.
mean_scheduled_duration: Counter<Microseconds> [],
/// The mean duration of polls.
mean_poll_duration: Counter<Microseconds> [],
/// The ratio between the number polls categorized as slow and fast.
slow_poll_ratio: Gauge<Percent> [],
/// The ratio of tasks exceeding [`long_delay_threshold`][TaskMonitor::long_delay_threshold].
long_delay_ratio: Gauge<Percent> [],
/// The mean duration of fast polls.
mean_fast_poll_duration: Counter<Microseconds> [],
/// The average time taken for a task with a short scheduling delay to be executed after being scheduled.
mean_short_delay_duration: Counter<Microseconds> [],
/// The mean duration of slow polls.
mean_slow_poll_duration: Counter<Microseconds> [],
/// The average scheduling delay for a task which takes a long time to start executing after being scheduled.
mean_long_delay_duration: Counter<Microseconds> [],
}
unstable {}
unstable_derived {}
}
}

Expand Down
Loading