From c7f4e3a401ec1919e1a578abe5938df430f46fc9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 26 Jan 2019 21:12:16 +0300 Subject: show jemalloc --- crates/ra_ide_api/src/lib.rs | 5 +++++ crates/ra_ide_api/src/status.rs | 28 +++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index a7caac02d..dc531e068 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -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 = Result; #[derive(Default)] diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs index 0dde30ae0..686ab97d2 100644 --- a/crates/ra_ide_api/src/status.rs +++ b/crates/ra_ide_api/src/status.rs @@ -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>> 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); -- cgit v1.2.3