diff --git a/cranelift/src/clif-util.rs b/cranelift/src/clif-util.rs index b38d4c587a..13a6ba7d06 100755 --- a/cranelift/src/clif-util.rs +++ b/cranelift/src/clif-util.rs @@ -199,10 +199,12 @@ fn main() { } ("test", Some(rest_cmd)) => { 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("time-passes"), &get_vec(rest_cmd.values_of("file")), - ).map(|_time| ()) + ).map(|_time| ()); + result } ("pass", Some(rest_cmd)) => { handle_debug_flag(rest_cmd.is_present("debug")); @@ -215,6 +217,7 @@ fn main() { // Can be unwrapped because 'single-file' is required cranelift_filetests::run_passes( rest_cmd.is_present("verbose"), + rest_cmd.is_present("time-passes"), &get_vec(rest_cmd.values_of("pass")), target_val, rest_cmd.value_of("single-file").unwrap(), @@ -235,6 +238,7 @@ fn main() { compile::run( get_vec(rest_cmd.values_of("file")), rest_cmd.is_present("print"), + rest_cmd.is_present("time-passes"), &get_vec(rest_cmd.values_of("set")), target_val, ) @@ -257,6 +261,7 @@ fn main() { &get_vec(rest_cmd.values_of("set")), target_val, rest_cmd.is_present("print-size"), + rest_cmd.is_present("time-passes"), ); #[cfg(not(feature = "wasm"))] diff --git a/cranelift/src/compile.rs b/cranelift/src/compile.rs index 5a93daa5a2..59402ff97f 100644 --- a/cranelift/src/compile.rs +++ b/cranelift/src/compile.rs @@ -3,6 +3,7 @@ use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::print_errors::pretty_error; use cranelift_codegen::settings::FlagsOrIsa; +use cranelift_codegen::timing; use cranelift_codegen::Context; use cranelift_codegen::{binemit, ir}; use cranelift_reader::parse_test; @@ -60,6 +61,7 @@ impl binemit::TrapSink for PrintTraps { pub fn run( files: Vec, flag_print: bool, + flag_report_times: bool, flag_set: &[String], flag_isa: &str, ) -> Result<(), String> { @@ -68,13 +70,20 @@ pub fn run( for filename in files { let path = Path::new(&filename); 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(()) } fn handle_module( flag_print: bool, + flag_report_times: bool, path: &PathBuf, name: &str, fisa: FlagsOrIsa, @@ -134,6 +143,10 @@ fn handle_module( } } + if flag_report_times { + print!("{}", timing::take_current()); + } + Ok(()) } diff --git a/cranelift/src/wasm.rs b/cranelift/src/wasm.rs index 3e91c3e7b0..3dd1269980 100644 --- a/cranelift/src/wasm.rs +++ b/cranelift/src/wasm.rs @@ -10,6 +10,7 @@ use cranelift_codegen::print_errors::{pretty_error, pretty_verifier_error}; use cranelift_codegen::settings::FlagsOrIsa; use cranelift_codegen::Context; +use cranelift_codegen::timing; use cranelift_entity::EntityRef; use cranelift_wasm::{ translate_module, DummyEnvironment, FuncIndex, ModuleEnvironment, ReturnMode, @@ -46,6 +47,7 @@ pub fn run( flag_set: &[String], flag_triple: &str, flag_print_size: bool, + flag_report_times: bool, ) -> Result<(), String> { let parsed = parse_sets_and_triple(flag_set, flag_triple)?; @@ -58,6 +60,7 @@ pub fn run( flag_check_translation, flag_print, flag_print_size, + flag_report_times, &path.to_path_buf(), &name, parsed.as_fisa(), @@ -72,6 +75,7 @@ fn handle_module( flag_check_translation: bool, flag_print: bool, flag_print_size: bool, + flag_report_times: bool, path: &PathBuf, name: &str, fisa: FlagsOrIsa, @@ -209,6 +213,10 @@ fn handle_module( println!("Total module bytecode size: {} bytes", total_bytecode_size); } + if flag_report_times { + println!("{}", timing::take_current()); + } + let _ = terminal.fg(term::color::GREEN); vprintln!(flag_verbose, "ok"); let _ = terminal.reset(); diff --git a/lib/filetests/src/lib.rs b/lib/filetests/src/lib.rs index 6d48eb9636..0032bc59db 100644 --- a/lib/filetests/src/lib.rs +++ b/lib/filetests/src/lib.rs @@ -35,6 +35,7 @@ extern crate num_cpus; #[macro_use] extern crate log; +use cranelift_codegen::timing; use cranelift_reader::TestCommand; use runner::TestRunner; use std::path::Path; @@ -73,8 +74,8 @@ type TestResult = Result; /// Directories are scanned recursively for test cases ending in `.clif`. These test cases are /// executed on background threads. /// -pub fn run(verbose: bool, files: &[String]) -> TestResult { - let mut runner = TestRunner::new(verbose); +pub fn run(verbose: bool, report_times: bool, files: &[String]) -> TestResult { + let mut runner = TestRunner::new(verbose, report_times); for path in files.iter().map(Path::new) { 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`. /// -pub fn run_passes(verbose: bool, passes: &[String], target: &str, file: &str) -> TestResult { - let mut runner = TestRunner::new(verbose); +pub fn run_passes( + 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); 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.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`. diff --git a/lib/filetests/src/runner.rs b/lib/filetests/src/runner.rs index ff6f203590..7840c0dfff 100644 --- a/lib/filetests/src/runner.rs +++ b/lib/filetests/src/runner.rs @@ -4,6 +4,7 @@ //! scanning directories for tests. use concurrent::{ConcurrentRunner, Reply}; +use cranelift_codegen::timing; use std::error::Error; use std::ffi::OsStr; use std::fmt::{self, Display}; @@ -62,6 +63,9 @@ impl Display for QueueEntry { pub struct TestRunner { verbose: bool, + // Should we print the timings out? + report_times: bool, + // Directories that have not yet been scanned. dir_stack: Vec, @@ -85,9 +89,10 @@ pub struct TestRunner { impl TestRunner { /// Create a new blank TrstRunner. - pub fn new(verbose: bool) -> Self { + pub fn new(verbose: bool, report_times: bool) -> Self { Self { verbose, + report_times, dir_stack: Vec::new(), tests: Vec::new(), new_tests: 0, @@ -300,6 +305,9 @@ impl TestRunner { } } conc.join(); + if self.report_times { + println!("{}", timing::take_current()); + } } }