aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/status.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/status.rs')
-rw-r--r--crates/ra_ide_api/src/status.rs50
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 @@
1use std::fmt;
2
3use ra_syntax::AstNode;
1use ra_db::{ 4use ra_db::{
2 SourceFileQuery, 5 SourceFileQuery,
3 salsa::{Database, debug::DebugQueryTable}, 6 salsa::{Database, debug::DebugQueryTable},
@@ -6,10 +9,53 @@ use ra_db::{
6use crate::db::RootDatabase; 9use crate::db::RootDatabase;
7 10
8pub(crate) fn status(db: &RootDatabase) -> String { 11pub(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)]
34struct FilesStats {
35 total: usize,
36 retained: usize,
37 retained_size: usize,
38}
39
40impl 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
51fn 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}