1825: add quiet mode to analysis-stats r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-09-12 08:50:38 +00:00 committed by GitHub
commit d614f463de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 116 additions and 82 deletions

View file

@ -4,9 +4,14 @@ use ra_db::SourceDatabase;
use ra_hir::{Crate, HasBodySource, HasSource, HirDisplay, ImplItem, ModuleDef, Ty, TypeWalk}; use ra_hir::{Crate, HasBodySource, HasSource, HirDisplay, ImplItem, ModuleDef, Ty, TypeWalk};
use ra_syntax::AstNode; use ra_syntax::AstNode;
use crate::Result; use crate::{Result, Verbosity};
pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -> Result<()> { pub fn run(
verbosity: Verbosity,
memory_usage: bool,
path: &Path,
only: Option<&str>,
) -> Result<()> {
let db_load_time = Instant::now(); let db_load_time = Instant::now();
let (mut host, roots) = ra_batch::load_cargo(path)?; let (mut host, roots) = ra_batch::load_cargo(path)?;
let db = host.raw_database(); let db = host.raw_database();
@ -55,10 +60,14 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -
println!("Item Collection: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); println!("Item Collection: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage());
let inference_time = Instant::now(); let inference_time = Instant::now();
let bar = indicatif::ProgressBar::with_draw_target( let bar = match verbosity {
Verbosity::Verbose | Verbosity::Normal => indicatif::ProgressBar::with_draw_target(
funcs.len() as u64, funcs.len() as u64,
indicatif::ProgressDrawTarget::stderr_nohz(), indicatif::ProgressDrawTarget::stderr_nohz(),
); ),
Verbosity::Quiet => indicatif::ProgressBar::hidden(),
};
bar.set_style( bar.set_style(
indicatif::ProgressStyle::default_bar().template("{wide_bar} {pos}/{len}\n{msg}"), indicatif::ProgressStyle::default_bar().template("{wide_bar} {pos}/{len}\n{msg}"),
); );
@ -70,7 +79,7 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -
for f in funcs { for f in funcs {
let name = f.name(db); let name = f.name(db);
let mut msg = format!("processing: {}", name); let mut msg = format!("processing: {}", name);
if verbose { if verbosity.is_verbose() {
let src = f.source(db); let src = f.source(db);
let original_file = src.file_id.original_file(db); let original_file = src.file_id.original_file(db);
let path = db.file_relative_path(original_file); let path = db.file_relative_path(original_file);
@ -103,7 +112,7 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -
} }
if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr_id) { if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr_id) {
num_type_mismatches += 1; num_type_mismatches += 1;
if verbose { if verbosity.is_verbose() {
let src = f.expr_source(db, expr_id); let src = f.expr_source(db, expr_id);
if let Some(src) = src { if let Some(src) = src {
// FIXME: it might be nice to have a function (on Analysis?) that goes from Source<T> -> (LineCol, LineCol) directly // FIXME: it might be nice to have a function (on Analysis?) that goes from Source<T> -> (LineCol, LineCol) directly

View file

@ -38,6 +38,7 @@ FLAGS:
-h, --help Prints help information -h, --help Prints help information
--memory-usage --memory-usage
-v, --verbose -v, --verbose
-q, --quiet
OPTIONS: OPTIONS:
-o <ONLY> -o <ONLY>

View file

@ -12,6 +12,22 @@ use ra_syntax::{AstNode, SourceFile};
type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>; type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>;
#[derive(Clone, Copy)]
pub enum Verbosity {
Verbose,
Normal,
Quiet,
}
impl Verbosity {
fn is_verbose(&self) -> bool {
match self {
Verbosity::Verbose => true,
_ => false,
}
}
}
fn main() -> Result<()> { fn main() -> Result<()> {
Logger::with_env().start()?; Logger::with_env().start()?;
@ -67,7 +83,15 @@ fn main() -> Result<()> {
eprintln!("{}", help::ANALYSIS_STATS_HELP); eprintln!("{}", help::ANALYSIS_STATS_HELP);
return Ok(()); return Ok(());
} }
let verbose = matches.contains(["-v", "--verbose"]); let verbosity = match (
matches.contains(["-v", "--verbose"]),
matches.contains(["-q", "--quiet"]),
) {
(false, false) => Verbosity::Normal,
(false, true) => Verbosity::Quiet,
(true, false) => Verbosity::Verbose,
(true, true) => Err("Invalid flags: -q conflicts with -v")?,
};
let memory_usage = matches.contains("--memory-usage"); let memory_usage = matches.contains("--memory-usage");
let only = matches.value_from_str(["-o", "--only"])?.map(|v: String| v.to_owned()); let only = matches.value_from_str(["-o", "--only"])?.map(|v: String| v.to_owned());
let path = { let path = {
@ -79,7 +103,7 @@ fn main() -> Result<()> {
trailing.pop().unwrap() trailing.pop().unwrap()
}; };
analysis_stats::run( analysis_stats::run(
verbose, verbosity,
memory_usage, memory_usage,
path.as_ref(), path.as_ref(),
only.as_ref().map(String::as_ref), only.as_ref().map(String::as_ref),