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 /crates/rust-analyzer/src/cli.rs | |
parent | c007ac38307f4915fea367bbcaae137f97a10fbe (diff) |
Move print_memory_usage to cli.rs
Diffstat (limited to 'crates/rust-analyzer/src/cli.rs')
-rw-r--r-- | crates/rust-analyzer/src/cli.rs | 23 |
1 files changed, 22 insertions, 1 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 | } | ||