diff options
author | Aleksey Kladov <[email protected]> | 2019-01-25 13:10:34 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-25 13:16:42 +0000 |
commit | 8d68b76ba01dcd190e037e4d61a94d4c9d568bdd (patch) | |
tree | 07aa4db38ba212ab1e2af1b791c409e5407ac53b /crates/ra_ide_api/src | |
parent | 021e691997efc35c983808ee3470a060a3ec3e96 (diff) |
better stats
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/status.rs | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs index d499dd878..c184ca892 100644 --- a/crates/ra_ide_api/src/status.rs +++ b/crates/ra_ide_api/src/status.rs | |||
@@ -1,3 +1,6 @@ | |||
1 | use std::fmt; | ||
2 | |||
3 | use ra_syntax::AstNode; | ||
1 | use ra_db::{ | 4 | use ra_db::{ |
2 | SourceFileQuery, | 5 | SourceFileQuery, |
3 | salsa::{Database, debug::DebugQueryTable}, | 6 | salsa::{Database, debug::DebugQueryTable}, |
@@ -6,10 +9,53 @@ use ra_db::{ | |||
6 | use crate::db::RootDatabase; | 9 | use crate::db::RootDatabase; |
7 | 10 | ||
8 | pub(crate) fn status(db: &RootDatabase) -> String { | 11 | pub(crate) fn status(db: &RootDatabase) -> String { |
9 | let n_parsed_files = db.query(SourceFileQuery).entries::<Vec<_>>().len(); | 12 | let file_stats = { |
13 | let mut stats = FilesStats::default(); | ||
14 | for entry in db.query(SourceFileQuery).entries::<Vec<_>>() { | ||
15 | stats.total += 1; | ||
16 | if let Some(value) = entry.value { | ||
17 | stats.retained += 1; | ||
18 | stats.retained_size = stats | ||
19 | .retained_size | ||
20 | .checked_add(value.syntax().memory_size_of_subtree()) | ||
21 | .unwrap(); | ||
22 | } | ||
23 | } | ||
24 | stats | ||
25 | }; | ||
10 | let n_defs = { | 26 | let n_defs = { |
11 | let interner: &hir::HirInterner = db.as_ref(); | 27 | let interner: &hir::HirInterner = db.as_ref(); |
12 | interner.len() | 28 | interner.len() |
13 | }; | 29 | }; |
14 | format!("#n_parsed_files {}\n#n_defs {}\n", n_parsed_files, n_defs) | 30 | format!("{}\nn_defs {}\n", file_stats, n_defs) |
31 | } | ||
32 | |||
33 | #[derive(Default)] | ||
34 | struct FilesStats { | ||
35 | total: usize, | ||
36 | retained: usize, | ||
37 | retained_size: usize, | ||
38 | } | ||
39 | |||
40 | impl fmt::Display for FilesStats { | ||
41 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
42 | let (size, suff) = human_bytes(self.retained_size); | ||
43 | write!( | ||
44 | fmt, | ||
45 | "{} parsed_files, {} ({}{}) retained", | ||
46 | self.total, self.retained, size, suff | ||
47 | ) | ||
48 | } | ||
49 | } | ||
50 | |||
51 | fn human_bytes(bytes: usize) -> (usize, &'static str) { | ||
52 | if bytes < 4096 { | ||
53 | return (bytes, " bytes"); | ||
54 | } | ||
55 | let kb = bytes / 1024; | ||
56 | if kb < 4096 { | ||
57 | return (kb, "kb"); | ||
58 | } | ||
59 | let mb = kb / 1024; | ||
60 | (mb, "mb") | ||
15 | } | 61 | } |