show jemalloc
This commit is contained in:
@@ -59,6 +59,11 @@ pub use ra_db::{
|
||||
Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId
|
||||
};
|
||||
|
||||
// We use jemalloc mainly to get heap usage statistics, actual performance
|
||||
// differnece is not measures.
|
||||
#[global_allocator]
|
||||
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
||||
|
||||
pub type Cancelable<T> = Result<T, Canceled>;
|
||||
|
||||
#[derive(Default)]
|
||||
|
||||
@@ -30,11 +30,12 @@ pub(crate) fn status(db: &RootDatabase) -> String {
|
||||
interner.len()
|
||||
};
|
||||
format!(
|
||||
"{}\n{}\n{}\nn_defs {}\nGC {:?} seconds ago",
|
||||
"{}\n{}\n{}\nn_defs {}\n\njemalloc: {}\nGC {:?} seconds ago",
|
||||
files_stats,
|
||||
symbols_stats,
|
||||
syntax_tree_stats,
|
||||
n_defs,
|
||||
MemoryStats::current(),
|
||||
db.last_gc.elapsed().as_secs(),
|
||||
)
|
||||
}
|
||||
@@ -126,6 +127,31 @@ impl FromIterator<TableEntry<SourceRootId, Arc<SymbolIndex>>> for LibrarySymbols
|
||||
}
|
||||
}
|
||||
|
||||
struct MemoryStats {
|
||||
allocated: Bytes,
|
||||
resident: Bytes,
|
||||
}
|
||||
|
||||
impl MemoryStats {
|
||||
fn current() -> MemoryStats {
|
||||
jemalloc_ctl::epoch().unwrap();
|
||||
MemoryStats {
|
||||
allocated: Bytes(jemalloc_ctl::stats::allocated().unwrap()),
|
||||
resident: Bytes(jemalloc_ctl::stats::resident().unwrap()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for MemoryStats {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
fmt,
|
||||
"{} allocated {} resident",
|
||||
self.allocated, self.resident,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Bytes(usize);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user