Move thread_mem_usage module into measure/
This commit is contained in:
@ -11,4 +11,10 @@ license = "Apache-2.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
log = "0.4.8"
|
||||
solana-sdk = { path = "../sdk", version = "0.23.0" }
|
||||
solana-metrics = { path = "../metrics", version = "0.23.0" }
|
||||
|
||||
[target."cfg(unix)".dependencies]
|
||||
jemallocator = "0.3.2"
|
||||
jemalloc-ctl = "0.3.2"
|
||||
|
@ -1 +1,9 @@
|
||||
pub mod measure;
|
||||
pub mod thread_mem_usage;
|
||||
|
||||
#[cfg(unix)]
|
||||
extern crate jemallocator;
|
||||
|
||||
#[cfg(unix)]
|
||||
#[global_allocator]
|
||||
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
||||
|
39
measure/src/thread_mem_usage.rs
Normal file
39
measure/src/thread_mem_usage.rs
Normal file
@ -0,0 +1,39 @@
|
||||
#[cfg(unix)]
|
||||
use jemalloc_ctl::thread;
|
||||
|
||||
pub fn datapoint(_name: &'static str) {
|
||||
#[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(unix)]
|
||||
allocated: thread::ThreadLocal<u64>,
|
||||
}
|
||||
|
||||
impl Allocatedp {
|
||||
pub fn default() -> Self {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let allocated = thread::allocatedp::mib().unwrap();
|
||||
let allocated = allocated.read().unwrap();
|
||||
Self { allocated }
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
Self {}
|
||||
}
|
||||
|
||||
pub fn get(&self) -> u64 {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
self.allocated.get()
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
0
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user