mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
Move memory usage statistics to ra_prof
This commit is contained in:
parent
e18389d268
commit
18a1e092e9
9 changed files with 78 additions and 68 deletions
|
@ -16,9 +16,6 @@ unicase = "2.2.0"
|
|||
superslice = "1.0.0"
|
||||
rand = "0.6.5"
|
||||
|
||||
jemallocator = { version = "0.1.9", optional = true }
|
||||
jemalloc-ctl = { version = "0.2.0", optional = true }
|
||||
|
||||
ra_syntax = { path = "../ra_syntax" }
|
||||
ra_text_edit = { path = "../ra_text_edit" }
|
||||
ra_db = { path = "../ra_db" }
|
||||
|
@ -36,6 +33,3 @@ version = "0.9.0"
|
|||
# Disable `fork` feature to allow compiling on webassembly
|
||||
default-features = false
|
||||
features = ["std", "bit-set", "break-dead-code"]
|
||||
|
||||
[features]
|
||||
jemalloc = [ "jemallocator", "jemalloc-ctl" ]
|
||||
|
|
|
@ -74,12 +74,6 @@ pub use crate::{
|
|||
pub use ra_db::{Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId, Edition};
|
||||
pub use hir::Documentation;
|
||||
|
||||
// We use jemalloc mainly to get heap usage statistics, actual performance
|
||||
// difference is not measures.
|
||||
#[cfg(feature = "jemalloc")]
|
||||
#[global_allocator]
|
||||
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
||||
|
||||
pub type Cancelable<T> = Result<T, Canceled>;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -9,6 +9,7 @@ use ra_db::{
|
|||
FileTextQuery, SourceRootId,
|
||||
salsa::{Database, debug::{DebugQueryTable, TableEntry}},
|
||||
};
|
||||
use ra_prof::{Bytes, memory_usage};
|
||||
use hir::MacroFile;
|
||||
|
||||
use crate::{
|
||||
|
@ -34,7 +35,7 @@ pub(crate) fn status(db: &RootDatabase) -> String {
|
|||
symbols_stats,
|
||||
syntax_tree_stats,
|
||||
macro_syntax_tree_stats,
|
||||
MemoryStats::current(),
|
||||
memory_usage(),
|
||||
db.last_gc.elapsed().as_secs(),
|
||||
)
|
||||
}
|
||||
|
@ -138,54 +139,3 @@ impl FromIterator<TableEntry<SourceRootId, Arc<SymbolIndex>>> for LibrarySymbols
|
|||
res
|
||||
}
|
||||
}
|
||||
|
||||
struct MemoryStats {
|
||||
allocated: Bytes,
|
||||
resident: Bytes,
|
||||
}
|
||||
|
||||
impl MemoryStats {
|
||||
#[cfg(feature = "jemalloc")]
|
||||
fn current() -> MemoryStats {
|
||||
jemalloc_ctl::epoch().unwrap();
|
||||
MemoryStats {
|
||||
allocated: Bytes(jemalloc_ctl::stats::allocated().unwrap()),
|
||||
resident: Bytes(jemalloc_ctl::stats::resident().unwrap()),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "jemalloc"))]
|
||||
fn current() -> MemoryStats {
|
||||
MemoryStats { allocated: Bytes(0), resident: Bytes(0) }
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
impl fmt::Display for Bytes {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let bytes = self.0;
|
||||
if bytes < 4096 {
|
||||
return write!(f, "{} bytes", bytes);
|
||||
}
|
||||
let kb = bytes / 1024;
|
||||
if kb < 4096 {
|
||||
return write!(f, "{}kb", kb);
|
||||
}
|
||||
let mb = kb / 1024;
|
||||
write!(f, "{}mb", mb)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::AddAssign<usize> for Bytes {
|
||||
fn add_assign(&mut self, x: usize) {
|
||||
self.0 += x;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue