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
#[cfg(not(feature = "no-jemalloc"))]
#[cfg(unix)]
use jemalloc_ctl::thread;
pub fn datapoint(_name: &'static str) {
#[cfg(not(feature = "no-jemalloc"))]
#[cfg(unix)]
{
let allocated = thread::allocatedp::mib().unwrap();
let allocated = allocated.read().unwrap();
let mem = allocated.get();
solana_metrics::datapoint_debug!("thread-memory", (_name, mem as i64, i64));
}
}
pub struct Allocatedp {
#[cfg(not(feature = "no-jemalloc"))]
#[cfg(unix)]
allocated: thread::ThreadLocal<u64>,
}
impl Allocatedp {
pub fn default() -> Self {
#[cfg(not(feature = "no-jemalloc"))]
#[cfg(unix)]
{
let allocated = thread::allocatedp::mib().unwrap();
let allocated = allocated.read().unwrap();
Self { allocated }
}
#[cfg(any(feature = "no-jemalloc", not(unix)))]
Self {}
}
pub fn get(&self) -> u64 {
#[cfg(not(feature = "no-jemalloc"))]
#[cfg(unix)]
{
self.allocated.get()
}
#[cfg(any(feature = "no-jemalloc", not(unix)))]
0
}
pub fn since(&self, previous: u64) -> i64 {
self.get() as i64 - previous as i64
}
}