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
13 mod progress_report;
14
15 use std::io::Read;
16
17 use anyhow::Result;
18 use ide::AnalysisHost;
19 use vfs::Vfs;
20
21 #[derive(Clone, Copy)]
22 pub enum Verbosity {
23 Spammy,
24 Verbose,
25 Normal,
26 Quiet,
27 }
28
29 impl Verbosity {
is_verbose(self) -> bool30 pub fn is_verbose(self) -> bool {
31 matches!(self, Verbosity::Verbose | Verbosity::Spammy)
32 }
is_spammy(self) -> bool33 pub fn is_spammy(self) -> bool {
34 matches!(self, Verbosity::Spammy)
35 }
36 }
37
read_stdin() -> Result<String>38 fn read_stdin() -> Result<String> {
39 let mut buff = String::new();
40 std::io::stdin().read_to_string(&mut buff)?;
41 Ok(buff)
42 }
43
report_metric(metric: &str, value: u64, unit: &str)44 fn report_metric(metric: &str, value: u64, unit: &str) {
45 if std::env::var("RA_METRICS").is_err() {
46 return;
47 }
48 println!("METRIC:{}:{}:{}", metric, value, unit)
49 }
50
print_memory_usage(mut host: AnalysisHost, vfs: Vfs)51 fn print_memory_usage(mut host: AnalysisHost, vfs: Vfs) {
52 let mut mem = host.per_query_memory_usage();
53
54 let before = profile::memory_usage();
55 drop(vfs);
56 let vfs = before.allocated - profile::memory_usage().allocated;
57 mem.push(("VFS".into(), vfs));
58
59 let before = profile::memory_usage();
60 drop(host);
61 mem.push(("Unaccounted".into(), before.allocated - profile::memory_usage().allocated));
62
63 mem.push(("Remaining".into(), profile::memory_usage().allocated));
64
65 for (name, bytes) in mem {
66 // NOTE: Not a debug print, so avoid going through the `eprintln` defined above.
67 eprintln!("{:>8} {}", bytes, name);
68 }
69 }
70