diff options
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide_api/src/status.rs | 54 |
2 files changed, 2 insertions, 58 deletions
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index e61d5627e..28a74c003 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs | |||
@@ -74,12 +74,6 @@ pub use crate::{ | |||
74 | pub use ra_db::{Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId, Edition}; | 74 | pub use ra_db::{Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId, Edition}; |
75 | pub use hir::Documentation; | 75 | pub use hir::Documentation; |
76 | 76 | ||
77 | // We use jemalloc mainly to get heap usage statistics, actual performance | ||
78 | // difference is not measures. | ||
79 | #[cfg(feature = "jemalloc")] | ||
80 | #[global_allocator] | ||
81 | static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; | ||
82 | |||
83 | pub type Cancelable<T> = Result<T, Canceled>; | 77 | pub type Cancelable<T> = Result<T, Canceled>; |
84 | 78 | ||
85 | #[derive(Debug)] | 79 | #[derive(Debug)] |
diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs index 0cdeb15eb..ce25f4a87 100644 --- a/crates/ra_ide_api/src/status.rs +++ b/crates/ra_ide_api/src/status.rs | |||
@@ -9,6 +9,7 @@ use ra_db::{ | |||
9 | FileTextQuery, SourceRootId, | 9 | FileTextQuery, SourceRootId, |
10 | salsa::{Database, debug::{DebugQueryTable, TableEntry}}, | 10 | salsa::{Database, debug::{DebugQueryTable, TableEntry}}, |
11 | }; | 11 | }; |
12 | use ra_prof::{Bytes, memory_usage}; | ||
12 | use hir::MacroFile; | 13 | use hir::MacroFile; |
13 | 14 | ||
14 | use crate::{ | 15 | use crate::{ |
@@ -34,7 +35,7 @@ pub(crate) fn status(db: &RootDatabase) -> String { | |||
34 | symbols_stats, | 35 | symbols_stats, |
35 | syntax_tree_stats, | 36 | syntax_tree_stats, |
36 | macro_syntax_tree_stats, | 37 | macro_syntax_tree_stats, |
37 | MemoryStats::current(), | 38 | memory_usage(), |
38 | db.last_gc.elapsed().as_secs(), | 39 | db.last_gc.elapsed().as_secs(), |
39 | ) | 40 | ) |
40 | } | 41 | } |
@@ -138,54 +139,3 @@ impl FromIterator<TableEntry<SourceRootId, Arc<SymbolIndex>>> for LibrarySymbols | |||
138 | res | 139 | res |
139 | } | 140 | } |
140 | } | 141 | } |
141 | |||
142 | struct MemoryStats { | ||
143 | allocated: Bytes, | ||
144 | resident: Bytes, | ||
145 | } | ||
146 | |||
147 | impl MemoryStats { | ||
148 | #[cfg(feature = "jemalloc")] | ||
149 | fn current() -> MemoryStats { | ||
150 | jemalloc_ctl::epoch().unwrap(); | ||
151 | MemoryStats { | ||
152 | allocated: Bytes(jemalloc_ctl::stats::allocated().unwrap()), | ||
153 | resident: Bytes(jemalloc_ctl::stats::resident().unwrap()), | ||
154 | } | ||
155 | } | ||
156 | |||
157 | #[cfg(not(feature = "jemalloc"))] | ||
158 | fn current() -> MemoryStats { | ||
159 | MemoryStats { allocated: Bytes(0), resident: Bytes(0) } | ||
160 | } | ||
161 | } | ||
162 | |||
163 | impl fmt::Display for MemoryStats { | ||
164 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
165 | write!(fmt, "{} allocated {} resident", self.allocated, self.resident,) | ||
166 | } | ||
167 | } | ||
168 | |||
169 | #[derive(Default)] | ||
170 | struct Bytes(usize); | ||
171 | |||
172 | impl fmt::Display for Bytes { | ||
173 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
174 | let bytes = self.0; | ||
175 | if bytes < 4096 { | ||
176 | return write!(f, "{} bytes", bytes); | ||
177 | } | ||
178 | let kb = bytes / 1024; | ||
179 | if kb < 4096 { | ||
180 | return write!(f, "{}kb", kb); | ||
181 | } | ||
182 | let mb = kb / 1024; | ||
183 | write!(f, "{}mb", mb) | ||
184 | } | ||
185 | } | ||
186 | |||
187 | impl std::ops::AddAssign<usize> for Bytes { | ||
188 | fn add_assign(&mut self, x: usize) { | ||
189 | self.0 += x; | ||
190 | } | ||
191 | } | ||