diff options
author | Jonas Schievink <[email protected]> | 2020-12-11 17:24:27 +0000 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-12-11 17:24:27 +0000 |
commit | 2fdde98b5c3b4e94276b83b7fe4654b9785945ad (patch) | |
tree | 709ffe32fd018b9d2ab080d8155339b9d4603608 | |
parent | c007ac38307f4915fea367bbcaae137f97a10fbe (diff) |
Move print_memory_usage to cli.rs
-rw-r--r-- | crates/rust-analyzer/src/cli.rs | 23 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_bench.rs | 5 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_stats.rs | 8 | ||||
-rw-r--r-- | crates/rust-analyzer/src/lib.rs | 22 |
4 files changed, 26 insertions, 32 deletions
diff --git a/crates/rust-analyzer/src/cli.rs b/crates/rust-analyzer/src/cli.rs index 6966ee576..6879a462d 100644 --- a/crates/rust-analyzer/src/cli.rs +++ b/crates/rust-analyzer/src/cli.rs | |||
@@ -10,8 +10,9 @@ mod ssr; | |||
10 | use std::io::Read; | 10 | use std::io::Read; |
11 | 11 | ||
12 | use anyhow::Result; | 12 | use anyhow::Result; |
13 | use ide::Analysis; | 13 | use ide::{Analysis, AnalysisHost}; |
14 | use syntax::{AstNode, SourceFile}; | 14 | use syntax::{AstNode, SourceFile}; |
15 | use vfs::Vfs; | ||
15 | 16 | ||
16 | pub use self::{ | 17 | pub use self::{ |
17 | analysis_bench::{BenchCmd, BenchWhat, Position}, | 18 | analysis_bench::{BenchCmd, BenchWhat, Position}, |
@@ -82,3 +83,23 @@ fn report_metric(metric: &str, value: u64, unit: &str) { | |||
82 | } | 83 | } |
83 | println!("METRIC:{}:{}:{}", metric, value, unit) | 84 | println!("METRIC:{}:{}:{}", metric, value, unit) |
84 | } | 85 | } |
86 | |||
87 | fn print_memory_usage(mut host: AnalysisHost, vfs: Vfs) { | ||
88 | let mut mem = host.per_query_memory_usage(); | ||
89 | |||
90 | let before = profile::memory_usage(); | ||
91 | drop(vfs); | ||
92 | let vfs = before.allocated - profile::memory_usage().allocated; | ||
93 | mem.push(("VFS".into(), vfs)); | ||
94 | |||
95 | let before = profile::memory_usage(); | ||
96 | drop(host); | ||
97 | mem.push(("Unaccounted".into(), before.allocated - profile::memory_usage().allocated)); | ||
98 | |||
99 | mem.push(("Remaining".into(), profile::memory_usage().allocated)); | ||
100 | |||
101 | for (name, bytes) in mem { | ||
102 | // NOTE: Not a debug print, so avoid going through the `eprintln` defined above. | ||
103 | eprintln!("{:>8} {}", bytes, name); | ||
104 | } | ||
105 | } | ||
diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs index 8e33986d5..5a8484c62 100644 --- a/crates/rust-analyzer/src/cli/analysis_bench.rs +++ b/crates/rust-analyzer/src/cli/analysis_bench.rs | |||
@@ -12,10 +12,7 @@ use ide_db::base_db::{ | |||
12 | }; | 12 | }; |
13 | use vfs::AbsPathBuf; | 13 | use vfs::AbsPathBuf; |
14 | 14 | ||
15 | use crate::{ | 15 | use crate::cli::{load_cargo::load_cargo, print_memory_usage, Verbosity}; |
16 | cli::{load_cargo::load_cargo, Verbosity}, | ||
17 | print_memory_usage, | ||
18 | }; | ||
19 | 16 | ||
20 | pub struct BenchCmd { | 17 | pub struct BenchCmd { |
21 | pub path: PathBuf, | 18 | pub path: PathBuf, |
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 58d284d47..a23fb7a33 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs | |||
@@ -23,11 +23,9 @@ use rustc_hash::FxHashSet; | |||
23 | use stdx::format_to; | 23 | use stdx::format_to; |
24 | use syntax::AstNode; | 24 | use syntax::AstNode; |
25 | 25 | ||
26 | use crate::{ | 26 | use crate::cli::{ |
27 | cli::{ | 27 | load_cargo::load_cargo, print_memory_usage, progress_report::ProgressReport, report_metric, |
28 | load_cargo::load_cargo, progress_report::ProgressReport, report_metric, Result, Verbosity, | 28 | Result, Verbosity, |
29 | }, | ||
30 | print_memory_usage, | ||
31 | }; | 29 | }; |
32 | use profile::StopWatch; | 30 | use profile::StopWatch; |
33 | 31 | ||
diff --git a/crates/rust-analyzer/src/lib.rs b/crates/rust-analyzer/src/lib.rs index b82deaf0d..79fe30e53 100644 --- a/crates/rust-analyzer/src/lib.rs +++ b/crates/rust-analyzer/src/lib.rs | |||
@@ -37,10 +37,8 @@ mod document; | |||
37 | pub mod lsp_ext; | 37 | pub mod lsp_ext; |
38 | pub mod config; | 38 | pub mod config; |
39 | 39 | ||
40 | use ide::AnalysisHost; | ||
41 | use serde::de::DeserializeOwned; | 40 | use serde::de::DeserializeOwned; |
42 | use std::fmt; | 41 | use std::fmt; |
43 | use vfs::Vfs; | ||
44 | 42 | ||
45 | pub use crate::{caps::server_capabilities, main_loop::main_loop}; | 43 | pub use crate::{caps::server_capabilities, main_loop::main_loop}; |
46 | 44 | ||
@@ -72,23 +70,3 @@ impl fmt::Display for LspError { | |||
72 | } | 70 | } |
73 | 71 | ||
74 | impl std::error::Error for LspError {} | 72 | impl std::error::Error for LspError {} |
75 | |||
76 | fn print_memory_usage(mut host: AnalysisHost, vfs: Vfs) { | ||
77 | let mut mem = host.per_query_memory_usage(); | ||
78 | |||
79 | let before = profile::memory_usage(); | ||
80 | drop(vfs); | ||
81 | let vfs = before.allocated - profile::memory_usage().allocated; | ||
82 | mem.push(("VFS".into(), vfs)); | ||
83 | |||
84 | let before = profile::memory_usage(); | ||
85 | drop(host); | ||
86 | mem.push(("Unaccounted".into(), before.allocated - profile::memory_usage().allocated)); | ||
87 | |||
88 | mem.push(("Remaining".into(), profile::memory_usage().allocated)); | ||
89 | |||
90 | for (name, bytes) in mem { | ||
91 | // NOTE: Not a debug print, so avoid going through the `eprintln` defined above. | ||
92 | std::eprintln!("{:>8} {}", bytes, name); | ||
93 | } | ||
94 | } | ||