pub struct TaskMonitorCore { /* private fields */ }Expand description
A non-Clone, non-allocated, static-friendly version of TaskMonitor.
See full docs on the TaskMonitor struct.
You should use TaskMonitorCore if you have a known count of monitors
that you want to initialize as compile-time static structs.
You can also use TaskMonitorCore if you are already passing around an Arc-wrapped
struct that you want to store your monitor in. This way, you can avoid double-Arc’ing it.
For other most other non-static usage, TaskMonitor will be more ergonomic.
§Examples
Static usage:
use tokio_metrics::TaskMonitorCore;
static MONITOR: TaskMonitorCore = TaskMonitorCore::new();
#[tokio::main]
async fn main() {
assert_eq!(MONITOR.cumulative().first_poll_count, 0);
MONITOR.instrument(async {}).await;
assert_eq!(MONITOR.cumulative().first_poll_count, 1);
}Usage with wrapper struct and TaskMonitorCore::instrument_with:
use std::sync::Arc;
use tokio_metrics::TaskMonitorCore;
#[derive(Clone)]
struct SharedState(Arc<SharedStateInner>);
struct SharedStateInner {
monitor: TaskMonitorCore,
other_state: SomeOtherSharedState,
}
/// Imagine: a type that wasn't `Clone` that you want to pass around
/// in a similar way as the monitor
struct SomeOtherSharedState;
impl AsRef<TaskMonitorCore> for SharedState {
fn as_ref(&self) -> &TaskMonitorCore {
&self.0.monitor
}
}
#[tokio::main]
async fn main() {
let state = SharedState(Arc::new(SharedStateInner {
monitor: TaskMonitorCore::new(),
other_state: SomeOtherSharedState,
}));
assert_eq!(state.0.monitor.cumulative().first_poll_count, 0);
TaskMonitorCore::instrument_with(async {}, state.clone()).await;
assert_eq!(state.0.monitor.cumulative().first_poll_count, 1);
}Implementations§
Source§impl TaskMonitorCore
impl TaskMonitorCore
Sourcepub const fn builder() -> TaskMonitorCoreBuilder
pub const fn builder() -> TaskMonitorCoreBuilder
Returns a const-friendly TaskMonitorCoreBuilder.
Sourcepub const fn new() -> TaskMonitorCore
pub const fn new() -> TaskMonitorCore
Constructs a new TaskMonitorCore. Refer to the struct documentation for more discussion
of benefits compared to TaskMonitor.
Uses TaskMonitor::DEFAULT_SLOW_POLL_THRESHOLD as the threshold at which polls will be
considered ‘slow’.
Uses TaskMonitor::DEFAULT_LONG_DELAY_THRESHOLD as the threshold at which scheduling will be
considered ‘long’.
Sourcepub const fn with_slow_poll_threshold(
slow_poll_cut_off: Duration,
) -> TaskMonitorCore
pub const fn with_slow_poll_threshold( slow_poll_cut_off: Duration, ) -> TaskMonitorCore
Constructs a new task monitor with a given threshold at which polls are considered ‘slow’.
Refer to TaskMonitor::with_slow_poll_threshold for examples.
Sourcepub fn slow_poll_threshold(&self) -> Duration
pub fn slow_poll_threshold(&self) -> Duration
Produces the duration greater-than-or-equal-to at which polls are categorized as slow.
Refer to TaskMonitor::slow_poll_threshold for examples.
Sourcepub fn long_delay_threshold(&self) -> Duration
pub fn long_delay_threshold(&self) -> Duration
Produces the duration greater-than-or-equal-to at which scheduling delays are categorized as long.
Sourcepub fn instrument<F>(&'static self, task: F) -> Instrumented<F, &'static Self> ⓘ
pub fn instrument<F>(&'static self, task: F) -> Instrumented<F, &'static Self> ⓘ
Produces an instrumented façade around a given async task.
§Examples
use tokio_metrics::TaskMonitorCore;
static MONITOR: TaskMonitorCore = TaskMonitorCore::new();
#[tokio::main]
async fn main() {
assert_eq!(MONITOR.cumulative().first_poll_count, 0);
MONITOR.instrument(async {}).await;
assert_eq!(MONITOR.cumulative().first_poll_count, 1);
}Sourcepub fn instrument_with<F, M: AsRef<TaskMonitorCore> + Send + Sync + 'static>(
task: F,
monitor: M,
) -> Instrumented<F, M> ⓘ
pub fn instrument_with<F, M: AsRef<TaskMonitorCore> + Send + Sync + 'static>( task: F, monitor: M, ) -> Instrumented<F, M> ⓘ
Produces an instrumented façade around a given async task, with an explicit monitor.
Use this when you have a non-static monitor reference, such as an Arc<TaskMonitorCore>.
§Examples
use std::sync::Arc;
use tokio_metrics::TaskMonitorCore;
#[derive(Clone)]
struct SharedState(Arc<SharedStateInner>);
struct SharedStateInner {
monitor: TaskMonitorCore,
other_state: SomeOtherSharedState,
}
/// Imagine: a type that wasn't `Clone` that you want to pass around
/// in a similar way as the monitor
struct SomeOtherSharedState;
impl AsRef<TaskMonitorCore> for SharedState {
fn as_ref(&self) -> &TaskMonitorCore {
&self.0.monitor
}
}
#[tokio::main]
async fn main() {
let state = SharedState(Arc::new(SharedStateInner {
monitor: TaskMonitorCore::new(),
other_state: SomeOtherSharedState,
}));
assert_eq!(state.0.monitor.cumulative().first_poll_count, 0);
TaskMonitorCore::instrument_with(async {}, state.clone()).await;
assert_eq!(state.0.monitor.cumulative().first_poll_count, 1);
}Sourcepub fn cumulative(&self) -> TaskMetrics
pub fn cumulative(&self) -> TaskMetrics
Produces TaskMetrics for the tasks instrumented by this TaskMonitorCore, collected since
the construction of TaskMonitorCore.
§See also
TaskMonitorCore::intervals: producesTaskMetricsfor user-defined sampling intervals, instead of cumulatively
See TaskMonitor::cumulative for examples.
Sourcepub fn intervals<Monitor: AsRef<TaskMonitorCore> + Send + Sync + 'static>(
monitor: Monitor,
) -> TaskIntervals<Monitor> ⓘ
pub fn intervals<Monitor: AsRef<TaskMonitorCore> + Send + Sync + 'static>( monitor: Monitor, ) -> TaskIntervals<Monitor> ⓘ
Produces an unending iterator of metric sampling intervals.
Each sampling interval is defined by the time elapsed between advancements of the iterator
produced by TaskMonitorCore::intervals. The item type of this iterator is TaskMetrics,
which is a bundle of task metrics that describe only events occurring within that sampling
interval.
§Examples
The below example demonstrates construction of TaskIntervals with TaskMonitorCore.
See TaskMonitor::intervals for more usage examples.
use std::sync::Arc;
fn main() {
let metrics_monitor = Arc::new(tokio_metrics::TaskMonitorCore::new());
let mut _intervals = tokio_metrics::TaskMonitorCore::intervals(metrics_monitor);
}Trait Implementations§
Source§impl AsRef<TaskMonitorCore> for TaskMonitor
impl AsRef<TaskMonitorCore> for TaskMonitor
Source§fn as_ref(&self) -> &TaskMonitorCore
fn as_ref(&self) -> &TaskMonitorCore
Source§impl AsRef<TaskMonitorCore> for TaskMonitorCore
impl AsRef<TaskMonitorCore> for TaskMonitorCore
Source§fn as_ref(&self) -> &TaskMonitorCore
fn as_ref(&self) -> &TaskMonitorCore
Source§impl Debug for TaskMonitorCore
impl Debug for TaskMonitorCore
Source§impl Default for TaskMonitorCore
impl Default for TaskMonitorCore
Source§fn default() -> TaskMonitorCore
fn default() -> TaskMonitorCore
Auto Trait Implementations§
impl !Freeze for TaskMonitorCore
impl RefUnwindSafe for TaskMonitorCore
impl Send for TaskMonitorCore
impl Sync for TaskMonitorCore
impl Unpin for TaskMonitorCore
impl UnsafeUnpin for TaskMonitorCore
impl UnwindSafe for TaskMonitorCore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<V, F> ValueFormatter<&V> for F
impl<V, F> ValueFormatter<&V> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &&V)
fn format_value(writer: impl ValueWriter, value: &&V)
value to writerSource§impl<V, F> ValueFormatter<Arc<V>> for F
impl<V, F> ValueFormatter<Arc<V>> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Arc<V>)
fn format_value(writer: impl ValueWriter, value: &Arc<V>)
value to writerSource§impl<V, F> ValueFormatter<Box<V>> for F
impl<V, F> ValueFormatter<Box<V>> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Box<V>)
fn format_value(writer: impl ValueWriter, value: &Box<V>)
value to writerSource§impl<V, F> ValueFormatter<Cow<'_, V>> for F
impl<V, F> ValueFormatter<Cow<'_, V>> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
value to writerSource§impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Option<V>)
fn format_value(writer: impl ValueWriter, value: &Option<V>)
value to writer