Add a compilation pass timing facility.
Individual compilation passes call the corresponding timing::*() function and hold on to their timing token while they run. This causes nested per-pass timing information to be recorded in thread-local storage. The --time-passes command line option prints a pass timing report to stdout.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
//! This module provides the `ConcurrentRunner` struct which uses a pool of threads to run tests
|
||||
//! concurrently.
|
||||
|
||||
use cretonne::timing;
|
||||
use std::panic::catch_unwind;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::mpsc::{channel, Sender, Receiver};
|
||||
@@ -33,7 +34,7 @@ pub struct ConcurrentRunner {
|
||||
// Workers have their own `Sender`.
|
||||
reply_rx: Receiver<Reply>,
|
||||
|
||||
handles: Vec<thread::JoinHandle<()>>,
|
||||
handles: Vec<thread::JoinHandle<timing::PassTimes>>,
|
||||
}
|
||||
|
||||
impl ConcurrentRunner {
|
||||
@@ -64,11 +65,13 @@ impl ConcurrentRunner {
|
||||
}
|
||||
|
||||
/// Join all the worker threads.
|
||||
/// Transfer pass timings from the worker threads to the current thread.
|
||||
pub fn join(&mut self) {
|
||||
assert!(self.request_tx.is_none(), "must shutdown before join");
|
||||
for h in self.handles.drain(..) {
|
||||
if let Err(e) = h.join() {
|
||||
println!("worker panicked: {:?}", e);
|
||||
match h.join() {
|
||||
Ok(t) => timing::add_to_current(t),
|
||||
Err(e) => println!("worker panicked: {:?}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,7 +112,7 @@ fn worker_thread(
|
||||
thread_num: usize,
|
||||
requests: Arc<Mutex<Receiver<Request>>>,
|
||||
replies: Sender<Reply>,
|
||||
) -> thread::JoinHandle<()> {
|
||||
) -> thread::JoinHandle<timing::PassTimes> {
|
||||
thread::Builder::new()
|
||||
.name(format!("worker #{}", thread_num))
|
||||
.spawn(move || {
|
||||
@@ -142,6 +145,10 @@ fn worker_thread(
|
||||
|
||||
replies.send(Reply::Done { jobid, result }).unwrap();
|
||||
}
|
||||
|
||||
// Timing is accumulated independently per thread.
|
||||
// Timings from this worker thread will be aggregated by `ConcurrentRunner::join()`.
|
||||
timing::take_current()
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use std::time;
|
||||
use cretonne::ir::Function;
|
||||
use cretonne::isa::TargetIsa;
|
||||
use cretonne::settings::Flags;
|
||||
use cretonne::timing;
|
||||
use cretonne::verify_function;
|
||||
use cton_reader::parse_test;
|
||||
use cton_reader::IsaSpec;
|
||||
@@ -17,6 +18,7 @@ use filetest::subtest::{SubTest, Context, Result};
|
||||
///
|
||||
/// If running this test causes a panic, it will propagate as normal.
|
||||
pub fn run(path: &Path) -> TestResult {
|
||||
let _tt = timing::process_file();
|
||||
dbg!("---\nFile: {}", path.to_string_lossy());
|
||||
let started = time::Instant::now();
|
||||
let buffer = read_to_string(path).map_err(|e| e.to_string())?;
|
||||
@@ -71,7 +73,6 @@ pub fn run(path: &Path) -> TestResult {
|
||||
}
|
||||
|
||||
|
||||
// TODO: Actually run the tests.
|
||||
Ok(started.elapsed())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user