• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::loom::sync::atomic::Ordering::Relaxed;
2 use crate::loom::sync::atomic::{AtomicU64, AtomicUsize};
3 
4 /// Retrieve runtime worker metrics.
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 #[repr(align(128))]
13 pub(crate) struct WorkerMetrics {
14     ///  Number of times the worker parked.
15     pub(crate) park_count: AtomicU64,
16 
17     /// Number of times the worker woke then parked again without doing work.
18     pub(crate) noop_count: AtomicU64,
19 
20     /// Number of tasks the worker stole.
21     pub(crate) steal_count: AtomicU64,
22 
23     /// Number of times the worker stole
24     pub(crate) steal_operations: AtomicU64,
25 
26     /// Number of tasks the worker polled.
27     pub(crate) poll_count: AtomicU64,
28 
29     /// Amount of time the worker spent doing work vs. parking.
30     pub(crate) busy_duration_total: AtomicU64,
31 
32     /// Number of tasks scheduled for execution on the worker's local queue.
33     pub(crate) local_schedule_count: AtomicU64,
34 
35     /// Number of tasks moved from the local queue to the global queue to free space.
36     pub(crate) overflow_count: AtomicU64,
37 
38     /// Number of tasks currently in the local queue. Used only by the
39     /// current-thread scheduler.
40     pub(crate) queue_depth: AtomicUsize,
41 }
42 
43 impl WorkerMetrics {
new() -> WorkerMetrics44     pub(crate) fn new() -> WorkerMetrics {
45         WorkerMetrics {
46             park_count: AtomicU64::new(0),
47             noop_count: AtomicU64::new(0),
48             steal_count: AtomicU64::new(0),
49             steal_operations: AtomicU64::new(0),
50             poll_count: AtomicU64::new(0),
51             overflow_count: AtomicU64::new(0),
52             busy_duration_total: AtomicU64::new(0),
53             local_schedule_count: AtomicU64::new(0),
54             queue_depth: AtomicUsize::new(0),
55         }
56     }
57 
queue_depth(&self) -> usize58     pub(crate) fn queue_depth(&self) -> usize {
59         self.queue_depth.load(Relaxed)
60     }
61 
set_queue_depth(&self, len: usize)62     pub(crate) fn set_queue_depth(&self, len: usize) {
63         self.queue_depth.store(len, Relaxed);
64     }
65 }
66