Skip to content

Commit c76e260

Browse files
committed
Use named threads in tidy
This makes it easier to profile.
1 parent 13afbda commit c76e260

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/tools/tidy/src/main.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::path::PathBuf;
1313
use std::process;
1414
use std::str::FromStr;
1515
use std::sync::atomic::{AtomicBool, Ordering};
16-
use std::thread::{scope, ScopedJoinHandle};
16+
use std::thread::{self, scope, ScopedJoinHandle};
1717

1818
fn main() {
1919
let root_path: PathBuf = env::args_os().nth(1).expect("need path to root of repo").into();
@@ -55,16 +55,28 @@ fn main() {
5555
VecDeque::with_capacity(concurrency.get());
5656

5757
macro_rules! check {
58-
($p:ident $(, $args:expr)* ) => {
58+
($p:ident) => {
59+
check!(@ $p, name=format!("{}", stringify!($p)));
60+
};
61+
($p:ident, $path:expr $(, $args:expr)* ) => {
62+
let shortened = $path.strip_prefix(&root_path).unwrap();
63+
let name = if shortened == std::path::Path::new("") {
64+
format!("{} (.)", stringify!($p))
65+
} else {
66+
format!("{} ({})", stringify!($p), shortened.display())
67+
};
68+
check!(@ $p, name=name, $path $(,$args)*);
69+
};
70+
(@ $p:ident, name=$name:expr $(, $args:expr)* ) => {
5971
drain_handles(&mut handles);
6072

61-
let handle = s.spawn(|| {
73+
let handle = thread::Builder::new().name($name).spawn_scoped(s, || {
6274
let mut flag = false;
6375
$p::check($($args, )* &mut flag);
6476
if (flag) {
6577
bad.store(true, Ordering::Relaxed);
6678
}
67-
});
79+
}).unwrap();
6880
handles.push_back(handle);
6981
}
7082
}

0 commit comments

Comments
 (0)