Revive the -T aka --time-passes argument to report run times on the CLI;

This commit is contained in:
Benjamin Bouvier
2018-10-15 20:17:25 +02:00
committed by Dan Gohman
parent 58229e10bf
commit af0a239539
5 changed files with 54 additions and 9 deletions

View File

@@ -199,10 +199,12 @@ fn main() {
} }
("test", Some(rest_cmd)) => { ("test", Some(rest_cmd)) => {
handle_debug_flag(rest_cmd.is_present("debug")); handle_debug_flag(rest_cmd.is_present("debug"));
cranelift_filetests::run( let result = cranelift_filetests::run(
rest_cmd.is_present("verbose"), rest_cmd.is_present("verbose"),
rest_cmd.is_present("time-passes"),
&get_vec(rest_cmd.values_of("file")), &get_vec(rest_cmd.values_of("file")),
).map(|_time| ()) ).map(|_time| ());
result
} }
("pass", Some(rest_cmd)) => { ("pass", Some(rest_cmd)) => {
handle_debug_flag(rest_cmd.is_present("debug")); handle_debug_flag(rest_cmd.is_present("debug"));
@@ -215,6 +217,7 @@ fn main() {
// Can be unwrapped because 'single-file' is required // Can be unwrapped because 'single-file' is required
cranelift_filetests::run_passes( cranelift_filetests::run_passes(
rest_cmd.is_present("verbose"), rest_cmd.is_present("verbose"),
rest_cmd.is_present("time-passes"),
&get_vec(rest_cmd.values_of("pass")), &get_vec(rest_cmd.values_of("pass")),
target_val, target_val,
rest_cmd.value_of("single-file").unwrap(), rest_cmd.value_of("single-file").unwrap(),
@@ -235,6 +238,7 @@ fn main() {
compile::run( compile::run(
get_vec(rest_cmd.values_of("file")), get_vec(rest_cmd.values_of("file")),
rest_cmd.is_present("print"), rest_cmd.is_present("print"),
rest_cmd.is_present("time-passes"),
&get_vec(rest_cmd.values_of("set")), &get_vec(rest_cmd.values_of("set")),
target_val, target_val,
) )
@@ -257,6 +261,7 @@ fn main() {
&get_vec(rest_cmd.values_of("set")), &get_vec(rest_cmd.values_of("set")),
target_val, target_val,
rest_cmd.is_present("print-size"), rest_cmd.is_present("print-size"),
rest_cmd.is_present("time-passes"),
); );
#[cfg(not(feature = "wasm"))] #[cfg(not(feature = "wasm"))]

View File

@@ -3,6 +3,7 @@
use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::isa::TargetIsa;
use cranelift_codegen::print_errors::pretty_error; use cranelift_codegen::print_errors::pretty_error;
use cranelift_codegen::settings::FlagsOrIsa; use cranelift_codegen::settings::FlagsOrIsa;
use cranelift_codegen::timing;
use cranelift_codegen::Context; use cranelift_codegen::Context;
use cranelift_codegen::{binemit, ir}; use cranelift_codegen::{binemit, ir};
use cranelift_reader::parse_test; use cranelift_reader::parse_test;
@@ -60,6 +61,7 @@ impl binemit::TrapSink for PrintTraps {
pub fn run( pub fn run(
files: Vec<String>, files: Vec<String>,
flag_print: bool, flag_print: bool,
flag_report_times: bool,
flag_set: &[String], flag_set: &[String],
flag_isa: &str, flag_isa: &str,
) -> Result<(), String> { ) -> Result<(), String> {
@@ -68,13 +70,20 @@ pub fn run(
for filename in files { for filename in files {
let path = Path::new(&filename); let path = Path::new(&filename);
let name = String::from(path.as_os_str().to_string_lossy()); let name = String::from(path.as_os_str().to_string_lossy());
handle_module(flag_print, &path.to_path_buf(), &name, parsed.as_fisa())?; handle_module(
flag_print,
flag_report_times,
&path.to_path_buf(),
&name,
parsed.as_fisa(),
)?;
} }
Ok(()) Ok(())
} }
fn handle_module( fn handle_module(
flag_print: bool, flag_print: bool,
flag_report_times: bool,
path: &PathBuf, path: &PathBuf,
name: &str, name: &str,
fisa: FlagsOrIsa, fisa: FlagsOrIsa,
@@ -134,6 +143,10 @@ fn handle_module(
} }
} }
if flag_report_times {
print!("{}", timing::take_current());
}
Ok(()) Ok(())
} }

View File

@@ -10,6 +10,7 @@
use cranelift_codegen::print_errors::{pretty_error, pretty_verifier_error}; use cranelift_codegen::print_errors::{pretty_error, pretty_verifier_error};
use cranelift_codegen::settings::FlagsOrIsa; use cranelift_codegen::settings::FlagsOrIsa;
use cranelift_codegen::Context; use cranelift_codegen::Context;
use cranelift_codegen::timing;
use cranelift_entity::EntityRef; use cranelift_entity::EntityRef;
use cranelift_wasm::{ use cranelift_wasm::{
translate_module, DummyEnvironment, FuncIndex, ModuleEnvironment, ReturnMode, translate_module, DummyEnvironment, FuncIndex, ModuleEnvironment, ReturnMode,
@@ -46,6 +47,7 @@ pub fn run(
flag_set: &[String], flag_set: &[String],
flag_triple: &str, flag_triple: &str,
flag_print_size: bool, flag_print_size: bool,
flag_report_times: bool,
) -> Result<(), String> { ) -> Result<(), String> {
let parsed = parse_sets_and_triple(flag_set, flag_triple)?; let parsed = parse_sets_and_triple(flag_set, flag_triple)?;
@@ -58,6 +60,7 @@ pub fn run(
flag_check_translation, flag_check_translation,
flag_print, flag_print,
flag_print_size, flag_print_size,
flag_report_times,
&path.to_path_buf(), &path.to_path_buf(),
&name, &name,
parsed.as_fisa(), parsed.as_fisa(),
@@ -72,6 +75,7 @@ fn handle_module(
flag_check_translation: bool, flag_check_translation: bool,
flag_print: bool, flag_print: bool,
flag_print_size: bool, flag_print_size: bool,
flag_report_times: bool,
path: &PathBuf, path: &PathBuf,
name: &str, name: &str,
fisa: FlagsOrIsa, fisa: FlagsOrIsa,
@@ -209,6 +213,10 @@ fn handle_module(
println!("Total module bytecode size: {} bytes", total_bytecode_size); println!("Total module bytecode size: {} bytes", total_bytecode_size);
} }
if flag_report_times {
println!("{}", timing::take_current());
}
let _ = terminal.fg(term::color::GREEN); let _ = terminal.fg(term::color::GREEN);
vprintln!(flag_verbose, "ok"); vprintln!(flag_verbose, "ok");
let _ = terminal.reset(); let _ = terminal.reset();

View File

@@ -35,6 +35,7 @@ extern crate num_cpus;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
use cranelift_codegen::timing;
use cranelift_reader::TestCommand; use cranelift_reader::TestCommand;
use runner::TestRunner; use runner::TestRunner;
use std::path::Path; use std::path::Path;
@@ -73,8 +74,8 @@ type TestResult = Result<time::Duration, String>;
/// Directories are scanned recursively for test cases ending in `.clif`. These test cases are /// Directories are scanned recursively for test cases ending in `.clif`. These test cases are
/// executed on background threads. /// executed on background threads.
/// ///
pub fn run(verbose: bool, files: &[String]) -> TestResult { pub fn run(verbose: bool, report_times: bool, files: &[String]) -> TestResult {
let mut runner = TestRunner::new(verbose); let mut runner = TestRunner::new(verbose, report_times);
for path in files.iter().map(Path::new) { for path in files.iter().map(Path::new) {
if path.is_file() { if path.is_file() {
@@ -93,8 +94,14 @@ pub fn run(verbose: bool, files: &[String]) -> TestResult {
/// ///
/// Directories are scanned recursively for test cases ending in `.clif`. /// Directories are scanned recursively for test cases ending in `.clif`.
/// ///
pub fn run_passes(verbose: bool, passes: &[String], target: &str, file: &str) -> TestResult { pub fn run_passes(
let mut runner = TestRunner::new(verbose); verbose: bool,
report_times: bool,
passes: &[String],
target: &str,
file: &str,
) -> TestResult {
let mut runner = TestRunner::new(verbose, /* report_times */ false);
let path = Path::new(file); let path = Path::new(file);
if path == Path::new("-") || path.is_file() { if path == Path::new("-") || path.is_file() {
@@ -103,7 +110,11 @@ pub fn run_passes(verbose: bool, passes: &[String], target: &str, file: &str) ->
runner.push_dir(path); runner.push_dir(path);
} }
runner.run_passes(passes, target) let result = runner.run_passes(passes, target);
if report_times {
println!("{}", timing::take_current());
}
result
} }
/// Create a new subcommand trait object to match `parsed.command`. /// Create a new subcommand trait object to match `parsed.command`.

View File

@@ -4,6 +4,7 @@
//! scanning directories for tests. //! scanning directories for tests.
use concurrent::{ConcurrentRunner, Reply}; use concurrent::{ConcurrentRunner, Reply};
use cranelift_codegen::timing;
use std::error::Error; use std::error::Error;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::fmt::{self, Display}; use std::fmt::{self, Display};
@@ -62,6 +63,9 @@ impl Display for QueueEntry {
pub struct TestRunner { pub struct TestRunner {
verbose: bool, verbose: bool,
// Should we print the timings out?
report_times: bool,
// Directories that have not yet been scanned. // Directories that have not yet been scanned.
dir_stack: Vec<PathBuf>, dir_stack: Vec<PathBuf>,
@@ -85,9 +89,10 @@ pub struct TestRunner {
impl TestRunner { impl TestRunner {
/// Create a new blank TrstRunner. /// Create a new blank TrstRunner.
pub fn new(verbose: bool) -> Self { pub fn new(verbose: bool, report_times: bool) -> Self {
Self { Self {
verbose, verbose,
report_times,
dir_stack: Vec::new(), dir_stack: Vec::new(),
tests: Vec::new(), tests: Vec::new(),
new_tests: 0, new_tests: 0,
@@ -300,6 +305,9 @@ impl TestRunner {
} }
} }
conc.join(); conc.join();
if self.report_times {
println!("{}", timing::take_current());
}
} }
} }