aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-26 18:12:16 +0000
committerAleksey Kladov <[email protected]>2019-01-27 19:57:18 +0000
commitc7f4e3a401ec1919e1a578abe5938df430f46fc9 (patch)
tree35954f48b7c50ba6e13fbd0bc4a66c7807225fca /crates/ra_ide_api
parent09b5dc8e02317c14cff80890f2d4591843322f47 (diff)
show jemalloc
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/Cargo.toml2
-rw-r--r--crates/ra_ide_api/src/lib.rs5
-rw-r--r--crates/ra_ide_api/src/status.rs28
3 files changed, 34 insertions, 1 deletions
diff --git a/crates/ra_ide_api/Cargo.toml b/crates/ra_ide_api/Cargo.toml
index 79e473463..ad9dd2088 100644
--- a/crates/ra_ide_api/Cargo.toml
+++ b/crates/ra_ide_api/Cargo.toml
@@ -14,6 +14,8 @@ fst = "0.3.1"
14rustc-hash = "1.0" 14rustc-hash = "1.0"
15parking_lot = "0.7.0" 15parking_lot = "0.7.0"
16unicase = "2.2.0" 16unicase = "2.2.0"
17jemallocator = "0.1.9"
18jemalloc-ctl = "0.2.0"
17 19
18ra_syntax = { path = "../ra_syntax" } 20ra_syntax = { path = "../ra_syntax" }
19ra_ide_api_light = { path = "../ra_ide_api_light" } 21ra_ide_api_light = { path = "../ra_ide_api_light" }
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::{
59 Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId 59 Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId
60}; 60};
61 61
62// We use jemalloc mainly to get heap usage statistics, actual performance
63// differnece is not measures.
64#[global_allocator]
65static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
66
62pub type Cancelable<T> = Result<T, Canceled>; 67pub type Cancelable<T> = Result<T, Canceled>;
63 68
64#[derive(Default)] 69#[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 {
30 interner.len() 30 interner.len()
31 }; 31 };
32 format!( 32 format!(
33 "{}\n{}\n{}\nn_defs {}\nGC {:?} seconds ago", 33 "{}\n{}\n{}\nn_defs {}\n\njemalloc: {}\nGC {:?} seconds ago",
34 files_stats, 34 files_stats,
35 symbols_stats, 35 symbols_stats,
36 syntax_tree_stats, 36 syntax_tree_stats,
37 n_defs, 37 n_defs,
38 MemoryStats::current(),
38 db.last_gc.elapsed().as_secs(), 39 db.last_gc.elapsed().as_secs(),
39 ) 40 )
40} 41}
@@ -126,6 +127,31 @@ impl FromIterator<TableEntry<SourceRootId, Arc<SymbolIndex>>> for LibrarySymbols
126 } 127 }
127} 128}
128 129
130struct MemoryStats {
131 allocated: Bytes,
132 resident: Bytes,
133}
134
135impl MemoryStats {
136 fn current() -> MemoryStats {
137 jemalloc_ctl::epoch().unwrap();
138 MemoryStats {
139 allocated: Bytes(jemalloc_ctl::stats::allocated().unwrap()),
140 resident: Bytes(jemalloc_ctl::stats::resident().unwrap()),
141 }
142 }
143}
144
145impl fmt::Display for MemoryStats {
146 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
147 write!(
148 fmt,
149 "{} allocated {} resident",
150 self.allocated, self.resident,
151 )
152 }
153}
154
129#[derive(Default)] 155#[derive(Default)]
130struct Bytes(usize); 156struct Bytes(usize);
131 157