From 2fdde98b5c3b4e94276b83b7fe4654b9785945ad Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 11 Dec 2020 18:24:27 +0100 Subject: Move print_memory_usage to cli.rs --- crates/rust-analyzer/src/cli.rs | 23 ++++++++++++++++++++++- crates/rust-analyzer/src/cli/analysis_bench.rs | 5 +---- crates/rust-analyzer/src/cli/analysis_stats.rs | 8 +++----- 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; use std::io::Read; use anyhow::Result; -use ide::Analysis; +use ide::{Analysis, AnalysisHost}; use syntax::{AstNode, SourceFile}; +use vfs::Vfs; pub use self::{ analysis_bench::{BenchCmd, BenchWhat, Position}, @@ -82,3 +83,23 @@ fn report_metric(metric: &str, value: u64, unit: &str) { } println!("METRIC:{}:{}:{}", metric, value, unit) } + +fn print_memory_usage(mut host: AnalysisHost, vfs: Vfs) { + let mut mem = host.per_query_memory_usage(); + + let before = profile::memory_usage(); + drop(vfs); + let vfs = before.allocated - profile::memory_usage().allocated; + mem.push(("VFS".into(), vfs)); + + let before = profile::memory_usage(); + drop(host); + mem.push(("Unaccounted".into(), before.allocated - profile::memory_usage().allocated)); + + mem.push(("Remaining".into(), profile::memory_usage().allocated)); + + for (name, bytes) in mem { + // NOTE: Not a debug print, so avoid going through the `eprintln` defined above. + eprintln!("{:>8} {}", bytes, name); + } +} 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::{ }; use vfs::AbsPathBuf; -use crate::{ - cli::{load_cargo::load_cargo, Verbosity}, - print_memory_usage, -}; +use crate::cli::{load_cargo::load_cargo, print_memory_usage, Verbosity}; pub struct BenchCmd { 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; use stdx::format_to; use syntax::AstNode; -use crate::{ - cli::{ - load_cargo::load_cargo, progress_report::ProgressReport, report_metric, Result, Verbosity, - }, - print_memory_usage, +use crate::cli::{ + load_cargo::load_cargo, print_memory_usage, progress_report::ProgressReport, report_metric, + Result, Verbosity, }; use profile::StopWatch; 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; pub mod lsp_ext; pub mod config; -use ide::AnalysisHost; use serde::de::DeserializeOwned; use std::fmt; -use vfs::Vfs; pub use crate::{caps::server_capabilities, main_loop::main_loop}; @@ -72,23 +70,3 @@ impl fmt::Display for LspError { } impl std::error::Error for LspError {} - -fn print_memory_usage(mut host: AnalysisHost, vfs: Vfs) { - let mut mem = host.per_query_memory_usage(); - - let before = profile::memory_usage(); - drop(vfs); - let vfs = before.allocated - profile::memory_usage().allocated; - mem.push(("VFS".into(), vfs)); - - let before = profile::memory_usage(); - drop(host); - mem.push(("Unaccounted".into(), before.allocated - profile::memory_usage().allocated)); - - mem.push(("Remaining".into(), profile::memory_usage().allocated)); - - for (name, bytes) in mem { - // NOTE: Not a debug print, so avoid going through the `eprintln` defined above. - std::eprintln!("{:>8} {}", bytes, name); - } -} -- cgit v1.2.3