1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use std::sync::atomic::{AtomicUsize, Ordering};
pub struct ThreadLoad {
term: AtomicUsize,
load: AtomicUsize,
threshold: usize,
}
impl ThreadLoad {
pub fn with_threshold(threshold: usize) -> Self {
ThreadLoad {
term: AtomicUsize::new(0),
load: AtomicUsize::new(0),
threshold,
}
}
#[allow(dead_code)]
pub fn get_threshold(&self) -> usize {
self.threshold
}
#[allow(dead_code)]
pub fn in_heavy_load(&self) -> bool {
self.load.load(Ordering::Relaxed) > self.threshold
}
#[allow(dead_code)]
pub fn term(&self) -> usize {
self.term.load(Ordering::Relaxed)
}
#[allow(dead_code)]
pub fn load(&self) -> usize {
self.load.load(Ordering::Relaxed)
}
}
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
pub use self::linux::*;
#[cfg(not(target_os = "linux"))]
mod other_os {
use super::ThreadLoad;
use std::sync::Arc;
use std::time::Instant;
pub struct ThreadLoadStatistics {}
impl ThreadLoadStatistics {
pub fn new(_slots: usize, _prefix: &str, _thread_load: Arc<ThreadLoad>) -> Self {
ThreadLoadStatistics {}
}
pub fn set_thread_target(&mut self, _target: usize) {}
pub fn record(&mut self, _instant: Instant) {}
}
}
#[cfg(not(target_os = "linux"))]
pub use self::other_os::ThreadLoadStatistics;