diff options
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide_api/src/status.rs | 28 |
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" | |||
14 | rustc-hash = "1.0" | 14 | rustc-hash = "1.0" |
15 | parking_lot = "0.7.0" | 15 | parking_lot = "0.7.0" |
16 | unicase = "2.2.0" | 16 | unicase = "2.2.0" |
17 | jemallocator = "0.1.9" | ||
18 | jemalloc-ctl = "0.2.0" | ||
17 | 19 | ||
18 | ra_syntax = { path = "../ra_syntax" } | 20 | ra_syntax = { path = "../ra_syntax" } |
19 | ra_ide_api_light = { path = "../ra_ide_api_light" } | 21 | ra_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] | ||
65 | static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; | ||
66 | |||
62 | pub type Cancelable<T> = Result<T, Canceled>; | 67 | pub 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 | ||
130 | struct MemoryStats { | ||
131 | allocated: Bytes, | ||
132 | resident: Bytes, | ||
133 | } | ||
134 | |||
135 | impl 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 | |||
145 | impl 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)] |
130 | struct Bytes(usize); | 156 | struct Bytes(usize); |
131 | 157 | ||