diff options
author | Aleksey Kladov <[email protected]> | 2019-06-30 12:40:01 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-06-30 12:49:45 +0100 |
commit | d70520eb38c3f39823186c3b352efe4c910417f1 (patch) | |
tree | 74cde977e61652f9bd0af6c62449037ac100e94f /crates/ra_prof/src | |
parent | 2ad8220f58675193860337a00fed87162a98dc1a (diff) |
print memory usage for queries
Diffstat (limited to 'crates/ra_prof/src')
-rw-r--r-- | crates/ra_prof/src/memory_usage.rs | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/crates/ra_prof/src/memory_usage.rs b/crates/ra_prof/src/memory_usage.rs index 2bde8fb5f..7f857942d 100644 --- a/crates/ra_prof/src/memory_usage.rs +++ b/crates/ra_prof/src/memory_usage.rs | |||
@@ -27,21 +27,23 @@ impl fmt::Display for MemoryUsage { | |||
27 | } | 27 | } |
28 | } | 28 | } |
29 | 29 | ||
30 | #[derive(Default)] | 30 | #[derive(Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)] |
31 | pub struct Bytes(usize); | 31 | pub struct Bytes(usize); |
32 | 32 | ||
33 | impl fmt::Display for Bytes { | 33 | impl fmt::Display for Bytes { |
34 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | 34 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
35 | let bytes = self.0; | 35 | let bytes = self.0; |
36 | if bytes < 4096 { | 36 | let mut value = bytes; |
37 | return write!(f, "{} bytes", bytes); | 37 | let mut suffix = "b"; |
38 | if value > 4096 { | ||
39 | value /= 1024; | ||
40 | suffix = "kb"; | ||
41 | if value > 4096 { | ||
42 | value /= 1024; | ||
43 | suffix = "mb"; | ||
44 | } | ||
38 | } | 45 | } |
39 | let kb = bytes / 1024; | 46 | f.pad(&format!("{}{}", value, suffix)) |
40 | if kb < 4096 { | ||
41 | return write!(f, "{}kb", kb); | ||
42 | } | ||
43 | let mb = kb / 1024; | ||
44 | write!(f, "{}mb", mb) | ||
45 | } | 47 | } |
46 | } | 48 | } |
47 | 49 | ||
@@ -50,3 +52,10 @@ impl std::ops::AddAssign<usize> for Bytes { | |||
50 | self.0 += x; | 52 | self.0 += x; |
51 | } | 53 | } |
52 | } | 54 | } |
55 | |||
56 | impl std::ops::Sub for Bytes { | ||
57 | type Output = Bytes; | ||
58 | fn sub(self, rhs: Bytes) -> Bytes { | ||
59 | Bytes(self.0 - rhs.0) | ||
60 | } | ||
61 | } | ||