]> git.proxmox.com Git - rustc.git/blame - src/tools/rust-analyzer/crates/rust-analyzer/src/cli.rs
New upstream version 1.65.0+dfsg1
[rustc.git] / src / tools / rust-analyzer / crates / rust-analyzer / src / cli.rs
CommitLineData
064997fb
FG
1//! Various batch processing tasks, intended primarily for debugging.
2
3pub mod flags;
4pub mod load_cargo;
5mod parse;
6mod symbols;
7mod highlight;
8mod analysis_stats;
9mod diagnostics;
10mod ssr;
11mod lsif;
f2b60f7d 12mod scip;
064997fb
FG
13
14mod progress_report;
15
16use std::io::Read;
17
18use anyhow::Result;
19use ide::AnalysisHost;
20use vfs::Vfs;
21
22#[derive(Clone, Copy)]
23pub enum Verbosity {
24 Spammy,
25 Verbose,
26 Normal,
27 Quiet,
28}
29
30impl Verbosity {
31 pub fn is_verbose(self) -> bool {
32 matches!(self, Verbosity::Verbose | Verbosity::Spammy)
33 }
34 pub fn is_spammy(self) -> bool {
35 matches!(self, Verbosity::Spammy)
36 }
37}
38
39fn read_stdin() -> Result<String> {
40 let mut buff = String::new();
41 std::io::stdin().read_to_string(&mut buff)?;
42 Ok(buff)
43}
44
45fn report_metric(metric: &str, value: u64, unit: &str) {
46 if std::env::var("RA_METRICS").is_err() {
47 return;
48 }
49 println!("METRIC:{}:{}:{}", metric, value, unit)
50}
51
52fn print_memory_usage(mut host: AnalysisHost, vfs: Vfs) {
53 let mut mem = host.per_query_memory_usage();
54
55 let before = profile::memory_usage();
56 drop(vfs);
57 let vfs = before.allocated - profile::memory_usage().allocated;
58 mem.push(("VFS".into(), vfs));
59
60 let before = profile::memory_usage();
61 drop(host);
62 mem.push(("Unaccounted".into(), before.allocated - profile::memory_usage().allocated));
63
64 mem.push(("Remaining".into(), profile::memory_usage().allocated));
65
66 for (name, bytes) in mem {
67 // NOTE: Not a debug print, so avoid going through the `eprintln` defined above.
68 eprintln!("{:>8} {}", bytes, name);
69 }
70}