Debian Codegraph @

third_party/rust/tokio/src/runtime/metrics/scheduler.rs

raw
1 use crate::loom::sync::atomic::Ordering::Relaxed;
2 use crate::util::metric_atomics::MetricAtomicU64;
3
4 /// Retrieves metrics from the Tokio runtime.
5 ///
6 /// **Note**: This is an [unstable API][unstable]. The public API of this type
7 /// may break in 1.x releases. See [the documentation on unstable
8 /// features][unstable] for details.
9 ///
10 /// [unstable]: crate#unstable-features
11 #[derive(Debug)]
12 pub(crate) struct SchedulerMetrics {
13 /// Number of tasks that are scheduled from outside the runtime.
14 pub(super) remote_schedule_count: MetricAtomicU64,
15 pub(super) budget_forced_yield_count: MetricAtomicU64,
16 }
17
18 impl SchedulerMetrics {
19 pub(crate) fn new() -> SchedulerMetrics {
20 SchedulerMetrics {
21 remote_schedule_count: MetricAtomicU64::new(0),
22 budget_forced_yield_count: MetricAtomicU64::new(0),
23 }
24 }
25
26 /// Increment the number of tasks scheduled externally
27 pub(crate) fn inc_remote_schedule_count(&self) {
28 self.remote_schedule_count.add(1, Relaxed);
29 }
30
31 /// Increment the number of tasks forced to yield due to budget exhaustion
32 pub(crate) fn inc_budget_forced_yield_count(&self) {
33 self.budget_forced_yield_count.add(1, Relaxed);
34 }
35 }