Skip to content

Commit 2fdde98

Browse files
Move print_memory_usage to cli.rs
1 parent c007ac3 commit 2fdde98

File tree

4 files changed

+26
-32
lines changed

4 files changed

+26
-32
lines changed

crates/rust-analyzer/src/cli.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ mod ssr;
1010
use std::io::Read;
1111

1212
use anyhow::Result;
13-
use ide::Analysis;
13+
use ide::{Analysis, AnalysisHost};
1414
use syntax::{AstNode, SourceFile};
15+
use vfs::Vfs;
1516

1617
pub use self::{
1718
analysis_bench::{BenchCmd, BenchWhat, Position},
@@ -82,3 +83,23 @@ fn report_metric(metric: &str, value: u64, unit: &str) {
8283
}
8384
println!("METRIC:{}:{}:{}", metric, value, unit)
8485
}
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+
}

crates/rust-analyzer/src/cli/analysis_bench.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ use ide_db::base_db::{
1212
};
1313
use vfs::AbsPathBuf;
1414

15-
use crate::{
16-
cli::{load_cargo::load_cargo, Verbosity},
17-
print_memory_usage,
18-
};
15+
use crate::cli::{load_cargo::load_cargo, print_memory_usage, Verbosity};
1916

2017
pub struct BenchCmd {
2118
pub path: PathBuf,

crates/rust-analyzer/src/cli/analysis_stats.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ use rustc_hash::FxHashSet;
2323
use stdx::format_to;
2424
use syntax::AstNode;
2525

26-
use crate::{
27-
cli::{
28-
load_cargo::load_cargo, progress_report::ProgressReport, report_metric, Result, Verbosity,
29-
},
30-
print_memory_usage,
26+
use crate::cli::{
27+
load_cargo::load_cargo, print_memory_usage, progress_report::ProgressReport, report_metric,
28+
Result, Verbosity,
3129
};
3230
use profile::StopWatch;
3331

crates/rust-analyzer/src/lib.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ mod document;
3737
pub mod lsp_ext;
3838
pub mod config;
3939

40-
use ide::AnalysisHost;
4140
use serde::de::DeserializeOwned;
4241
use std::fmt;
43-
use vfs::Vfs;
4442

4543
pub use crate::{caps::server_capabilities, main_loop::main_loop};
4644

@@ -72,23 +70,3 @@ impl fmt::Display for LspError {
7270
}
7371

7472
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-
}

0 commit comments

Comments
 (0)