tokio/runtime/scheduler/multi_thread/
counters.rs

1#[cfg(tokio_internal_mt_counters)]
2mod imp {
3    use std::sync::atomic::AtomicUsize;
4    use std::sync::atomic::Ordering::Relaxed;
5
6    static NUM_MAINTENANCE: AtomicUsize = AtomicUsize::new(0);
7    static NUM_NOTIFY_LOCAL: AtomicUsize = AtomicUsize::new(0);
8    static NUM_UNPARKS_LOCAL: AtomicUsize = AtomicUsize::new(0);
9    static NUM_LIFO_SCHEDULES: AtomicUsize = AtomicUsize::new(0);
10    static NUM_LIFO_CAPPED: AtomicUsize = AtomicUsize::new(0);
11
12    impl Drop for super::Counters {
13        fn drop(&mut self) {
14            let notifies_local = NUM_NOTIFY_LOCAL.load(Relaxed);
15            let unparks_local = NUM_UNPARKS_LOCAL.load(Relaxed);
16            let maintenance = NUM_MAINTENANCE.load(Relaxed);
17            let lifo_scheds = NUM_LIFO_SCHEDULES.load(Relaxed);
18            let lifo_capped = NUM_LIFO_CAPPED.load(Relaxed);
19
20            println!("---");
21            println!("notifies (local): {}", notifies_local);
22            println!(" unparks (local): {}", unparks_local);
23            println!("     maintenance: {}", maintenance);
24            println!("  LIFO schedules: {}", lifo_scheds);
25            println!("     LIFO capped: {}", lifo_capped);
26        }
27    }
28
29    pub(crate) fn inc_num_inc_notify_local() {
30        NUM_NOTIFY_LOCAL.fetch_add(1, Relaxed);
31    }
32
33    pub(crate) fn inc_num_unparks_local() {
34        NUM_UNPARKS_LOCAL.fetch_add(1, Relaxed);
35    }
36
37    pub(crate) fn inc_num_maintenance() {
38        NUM_MAINTENANCE.fetch_add(1, Relaxed);
39    }
40
41    pub(crate) fn inc_lifo_schedules() {
42        NUM_LIFO_SCHEDULES.fetch_add(1, Relaxed);
43    }
44
45    pub(crate) fn inc_lifo_capped() {
46        NUM_LIFO_CAPPED.fetch_add(1, Relaxed);
47    }
48}
49
50#[cfg(not(tokio_internal_mt_counters))]
51mod imp {
52    pub(crate) fn inc_num_inc_notify_local() {}
53    pub(crate) fn inc_num_unparks_local() {}
54    pub(crate) fn inc_num_maintenance() {}
55    pub(crate) fn inc_lifo_schedules() {}
56    pub(crate) fn inc_lifo_capped() {}
57}
58
59#[derive(Debug)]
60pub(crate) struct Counters;
61
62pub(super) use imp::*;