]> git.lizzy.rs Git - rust.git/blob - src/tools/rust-analyzer/crates/rust-analyzer/src/cli.rs
d5d877680a09a513a8392a2a0f3f50eee6da5b50
[rust.git] / src / tools / rust-analyzer / crates / rust-analyzer / src / cli.rs
1 //! Various batch processing tasks, intended primarily for debugging.
2
3 pub mod flags;
4 pub mod load_cargo;
5 mod parse;
6 mod symbols;
7 mod highlight;
8 mod analysis_stats;
9 mod diagnostics;
10 mod ssr;
11 mod lsif;
12 mod scip;
13
14 mod progress_report;
15
16 use std::io::Read;
17
18 use anyhow::Result;
19 use ide::AnalysisHost;
20 use vfs::Vfs;
21
22 #[derive(Clone, Copy)]
23 pub enum Verbosity {
24     Spammy,
25     Verbose,
26     Normal,
27     Quiet,
28 }
29
30 impl 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
39 fn read_stdin() -> Result<String> {
40     let mut buff = String::new();
41     std::io::stdin().read_to_string(&mut buff)?;
42     Ok(buff)
43 }
44
45 fn 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
52 fn 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!("{bytes:>8} {name}");
69     }
70 }