diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_prof/src/memory_usage.rs | 32 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_stats.rs | 14 |
2 files changed, 23 insertions, 23 deletions
diff --git a/crates/ra_prof/src/memory_usage.rs b/crates/ra_prof/src/memory_usage.rs index 857b51321..22b61e4a2 100644 --- a/crates/ra_prof/src/memory_usage.rs +++ b/crates/ra_prof/src/memory_usage.rs | |||
@@ -3,16 +3,30 @@ use std::fmt; | |||
3 | 3 | ||
4 | use cfg_if::cfg_if; | 4 | use cfg_if::cfg_if; |
5 | 5 | ||
6 | #[derive(Copy, Clone)] | ||
6 | pub struct MemoryUsage { | 7 | pub struct MemoryUsage { |
7 | pub allocated: Bytes, | 8 | pub allocated: Bytes, |
8 | } | 9 | } |
9 | 10 | ||
11 | impl fmt::Display for MemoryUsage { | ||
12 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
13 | write!(fmt, "{}", self.allocated) | ||
14 | } | ||
15 | } | ||
16 | |||
17 | impl std::ops::Sub for MemoryUsage { | ||
18 | type Output = MemoryUsage; | ||
19 | fn sub(self, rhs: MemoryUsage) -> MemoryUsage { | ||
20 | MemoryUsage { allocated: self.allocated - rhs.allocated } | ||
21 | } | ||
22 | } | ||
23 | |||
10 | impl MemoryUsage { | 24 | impl MemoryUsage { |
11 | pub fn current() -> MemoryUsage { | 25 | pub fn current() -> MemoryUsage { |
12 | cfg_if! { | 26 | cfg_if! { |
13 | if #[cfg(target_os = "linux")] { | 27 | if #[cfg(target_os = "linux")] { |
14 | // Note: This is incredibly slow. | 28 | // Note: This is incredibly slow. |
15 | let alloc = unsafe { libc::mallinfo() }.uordblks as u32 as usize; | 29 | let alloc = unsafe { libc::mallinfo() }.uordblks as u32 as isize; |
16 | MemoryUsage { allocated: Bytes(alloc) } | 30 | MemoryUsage { allocated: Bytes(alloc) } |
17 | } else { | 31 | } else { |
18 | MemoryUsage { allocated: Bytes(0) } | 32 | MemoryUsage { allocated: Bytes(0) } |
@@ -21,17 +35,11 @@ impl MemoryUsage { | |||
21 | } | 35 | } |
22 | } | 36 | } |
23 | 37 | ||
24 | impl fmt::Display for MemoryUsage { | ||
25 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
26 | write!(fmt, "{}", self.allocated) | ||
27 | } | ||
28 | } | ||
29 | |||
30 | #[derive(Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)] | 38 | #[derive(Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)] |
31 | pub struct Bytes(usize); | 39 | pub struct Bytes(isize); |
32 | 40 | ||
33 | impl Bytes { | 41 | impl Bytes { |
34 | pub fn megabytes(self) -> usize { | 42 | pub fn megabytes(self) -> isize { |
35 | self.0 / 1024 / 1024 | 43 | self.0 / 1024 / 1024 |
36 | } | 44 | } |
37 | } | 45 | } |
@@ -41,10 +49,10 @@ impl fmt::Display for Bytes { | |||
41 | let bytes = self.0; | 49 | let bytes = self.0; |
42 | let mut value = bytes; | 50 | let mut value = bytes; |
43 | let mut suffix = "b"; | 51 | let mut suffix = "b"; |
44 | if value > 4096 { | 52 | if value.abs() > 4096 { |
45 | value /= 1024; | 53 | value /= 1024; |
46 | suffix = "kb"; | 54 | suffix = "kb"; |
47 | if value > 4096 { | 55 | if value.abs() > 4096 { |
48 | value /= 1024; | 56 | value /= 1024; |
49 | suffix = "mb"; | 57 | suffix = "mb"; |
50 | } | 58 | } |
@@ -55,7 +63,7 @@ impl fmt::Display for Bytes { | |||
55 | 63 | ||
56 | impl std::ops::AddAssign<usize> for Bytes { | 64 | impl std::ops::AddAssign<usize> for Bytes { |
57 | fn add_assign(&mut self, x: usize) { | 65 | fn add_assign(&mut self, x: usize) { |
58 | self.0 += x; | 66 | self.0 += x as isize; |
59 | } | 67 | } |
60 | } | 68 | } |
61 | 69 | ||
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 66d201ba6..cf0d82b62 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs | |||
@@ -111,11 +111,7 @@ pub fn analysis_stats( | |||
111 | eprintln!("Total declarations: {}", num_decls); | 111 | eprintln!("Total declarations: {}", num_decls); |
112 | eprintln!("Total functions: {}", funcs.len()); | 112 | eprintln!("Total functions: {}", funcs.len()); |
113 | let item_collection_memory = ra_prof::memory_usage(); | 113 | let item_collection_memory = ra_prof::memory_usage(); |
114 | eprintln!( | 114 | eprintln!("Item Collection: {:?}, {}", analysis_time.elapsed(), item_collection_memory); |
115 | "Item Collection: {:?}, {}", | ||
116 | analysis_time.elapsed(), | ||
117 | item_collection_memory.allocated | ||
118 | ); | ||
119 | 115 | ||
120 | if randomize { | 116 | if randomize { |
121 | shuffle(&mut rng, &mut funcs); | 117 | shuffle(&mut rng, &mut funcs); |
@@ -140,7 +136,7 @@ pub fn analysis_stats( | |||
140 | eprintln!( | 136 | eprintln!( |
141 | "Parallel Inference: {:?}, {}", | 137 | "Parallel Inference: {:?}, {}", |
142 | inference_time.elapsed(), | 138 | inference_time.elapsed(), |
143 | ra_prof::memory_usage().allocated | 139 | ra_prof::memory_usage() |
144 | ); | 140 | ); |
145 | } | 141 | } |
146 | 142 | ||
@@ -297,11 +293,7 @@ pub fn analysis_stats( | |||
297 | 293 | ||
298 | let inference_time = inference_time.elapsed(); | 294 | let inference_time = inference_time.elapsed(); |
299 | let total_memory = ra_prof::memory_usage(); | 295 | let total_memory = ra_prof::memory_usage(); |
300 | eprintln!( | 296 | eprintln!("Inference: {:?}, {}", inference_time, total_memory - item_collection_memory); |
301 | "Inference: {:?}, {}", | ||
302 | inference_time, | ||
303 | total_memory.allocated - item_collection_memory.allocated | ||
304 | ); | ||
305 | 297 | ||
306 | let analysis_time = analysis_time.elapsed(); | 298 | let analysis_time = analysis_time.elapsed(); |
307 | eprintln!("Total: {:?}, {}", analysis_time, total_memory); | 299 | eprintln!("Total: {:?}, {}", analysis_time, total_memory); |