mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
show jemalloc
This commit is contained in:
parent
09b5dc8e02
commit
c7f4e3a401
4 changed files with 73 additions and 1 deletions
|
@ -14,6 +14,8 @@ fst = "0.3.1"
|
|||
rustc-hash = "1.0"
|
||||
parking_lot = "0.7.0"
|
||||
unicase = "2.2.0"
|
||||
jemallocator = "0.1.9"
|
||||
jemalloc-ctl = "0.2.0"
|
||||
|
||||
ra_syntax = { path = "../ra_syntax" }
|
||||
ra_ide_api_light = { path = "../ra_ide_api_light" }
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue