Support plugging external profilers into the Cranelift timing infrastructure (#5749)

* Remove no-std code for cranelift_codegen::timings

no-std mode isn't supported by Cranelift anymore

* Simplify define_passes macro

* Add egraph opt timings

* Replace the add_to_current api with PassTimes::add

* Omit a couple of unused time measurements

* Reduce divergence between run and run_passes a bit

* Introduce a Profiler trait

This allows plugging in external profilers into the Cranelift profiling
framework.

* Add Pass::description method

* Remove duplicate usage of the compile pass timing

* Rustfmt
This commit is contained in:
bjorn3
2023-03-10 20:33:56 +01:00
committed by GitHub
parent 0751cba6e2
commit 108f7917c8
5 changed files with 181 additions and 181 deletions

View File

@@ -82,14 +82,16 @@ impl ConcurrentRunner {
/// Join all the worker threads.
/// Transfer pass timings from the worker threads to the current thread.
pub fn join(&mut self) {
pub fn join(&mut self) -> timing::PassTimes {
assert!(self.request_tx.is_none(), "must shutdown before join");
let mut pass_times = timing::PassTimes::default();
for h in self.handles.drain(..) {
match h.join() {
Ok(t) => timing::add_to_current(&t),
Ok(t) => pass_times.add(&t),
Err(e) => println!("worker panicked: {:?}", e),
}
}
pass_times
}
/// Add a new job to the queues.

View File

@@ -24,10 +24,8 @@
pub use crate::function_runner::TestFileCompiler;
use crate::runner::TestRunner;
use cranelift_codegen::timing;
use cranelift_reader::TestCommand;
use std::path::Path;
use std::time;
mod concurrent;
pub mod function_runner;
@@ -63,7 +61,7 @@ mod test_wasm;
/// Directories are scanned recursively for test cases ending in `.clif`. These test cases are
/// executed on background threads.
///
pub fn run(verbose: bool, report_times: bool, files: &[String]) -> anyhow::Result<time::Duration> {
pub fn run(verbose: bool, report_times: bool, files: &[String]) -> anyhow::Result<()> {
let mut runner = TestRunner::new(verbose, report_times);
for path in files.iter().map(Path::new) {
@@ -89,8 +87,8 @@ pub fn run_passes(
passes: &[String],
target: &str,
file: &str,
) -> anyhow::Result<time::Duration> {
let mut runner = TestRunner::new(verbose, /* report_times */ false);
) -> anyhow::Result<()> {
let mut runner = TestRunner::new(verbose, report_times);
let path = Path::new(file);
if path == Path::new("-") || path.is_file() {
@@ -99,11 +97,8 @@ pub fn run_passes(
runner.push_dir(path);
}
let result = runner.run_passes(passes, target);
if report_times {
println!("{}", timing::take_current());
}
result
runner.start_threads();
runner.run_passes(passes, target)
}
/// Create a new subcommand trait object to match `parsed.command`.

View File

@@ -5,7 +5,6 @@
use crate::concurrent::{ConcurrentRunner, Reply};
use crate::runone;
use cranelift_codegen::timing;
use std::error::Error;
use std::ffi::OsStr;
use std::fmt::{self, Display};
@@ -298,9 +297,9 @@ impl TestRunner {
None => break,
}
}
conc.join();
let pass_times = conc.join();
if self.report_times {
println!("{}", timing::take_current());
println!("{}", pass_times);
}
}
}
@@ -355,8 +354,7 @@ impl TestRunner {
}
/// Scan pushed directories for tests and run them.
pub fn run(&mut self) -> anyhow::Result<time::Duration> {
let started = time::Instant::now();
pub fn run(&mut self) -> anyhow::Result<()> {
self.scan_dirs(IsPass::NotPass);
self.schedule_jobs();
self.report_slow_tests();
@@ -364,26 +362,22 @@ impl TestRunner {
println!("{} tests", self.tests.len());
match self.errors {
0 => Ok(started.elapsed()),
0 => Ok(()),
1 => anyhow::bail!("1 failure"),
n => anyhow::bail!("{} failures", n),
}
}
/// Scan pushed directories for tests and run specified passes from commandline on them.
pub fn run_passes(
&mut self,
passes: &[String],
target: &str,
) -> anyhow::Result<time::Duration> {
let started = time::Instant::now();
pub fn run_passes(&mut self, passes: &[String], target: &str) -> anyhow::Result<()> {
self.scan_dirs(IsPass::Pass);
self.schedule_pass_job(passes, target);
self.report_slow_tests();
self.drain_threads();
println!("{} tests", self.tests.len());
match self.errors {
0 => Ok(started.elapsed()),
0 => Ok(()),
1 => anyhow::bail!("1 failure"),
n => anyhow::bail!("{} failures", n),
}