lintcheck: add -j <N> option to configure threads.

defaults to 1
-j 0 choses the number of threads automtically (= number of physical cores)
This commit is contained in:
Matthias Krüger
2021-02-19 23:20:05 +01:00
parent 22aeec09e4
commit 8499a32859
2 changed files with 38 additions and 6 deletions

View File

@@ -229,10 +229,19 @@ impl Crate {
// "loop" the index within 0..thread_limit // "loop" the index within 0..thread_limit
let target_dir_index = index % thread_limit; let target_dir_index = index % thread_limit;
let perc = ((index * 100) as f32 / total_crates_to_lint as f32) as u8; let perc = ((index * 100) as f32 / total_crates_to_lint as f32) as u8;
if thread_limit == 1 {
println!(
"{}/{} {}% Linting {} {}",
index, total_crates_to_lint, perc, &self.name, &self.version
);
} else {
println!( println!(
"{}/{} {}% Linting {} {} in target dir {:?}", "{}/{} {}% Linting {} {} in target dir {:?}",
index, total_crates_to_lint, perc, &self.name, &self.version, target_dir_index index, total_crates_to_lint, perc, &self.name, &self.version, target_dir_index
); );
}
let cargo_clippy_path = std::fs::canonicalize(cargo_clippy_path).unwrap(); let cargo_clippy_path = std::fs::canonicalize(cargo_clippy_path).unwrap();
let shared_target_dir = clippy_project_root().join("target/lintcheck/shared_target_dir"); let shared_target_dir = clippy_project_root().join("target/lintcheck/shared_target_dir");
@@ -492,8 +501,23 @@ pub fn run(clap_config: &ArgMatches) {
// This helps when we check many small crates with dep-trees that don't have a lot of branches in // This helps when we check many small crates with dep-trees that don't have a lot of branches in
// order to achive some kind of parallelism // order to achive some kind of parallelism
// by default, use a single thread
let num_cpus = match clap_config.value_of("threads") {
Some(threads) => {
let threads: usize = threads
.parse()
.expect(&format!("Failed to parse '{}' to a digit", threads));
if threads == 0 {
// automatic choice
// Rayon seems to return thread count so half that for core count // Rayon seems to return thread count so half that for core count
let num_cpus: usize = rayon::current_num_threads() / 2; (rayon::current_num_threads() / 2) as usize
} else {
threads
}
},
// no -j passed, use a single thread
None => 1,
};
let num_crates = crates.len(); let num_crates = crates.len();

View File

@@ -69,6 +69,14 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
.value_name("CRATES-SOURCES-TOML-PATH") .value_name("CRATES-SOURCES-TOML-PATH")
.long("crates-toml") .long("crates-toml")
.help("set the path for a crates.toml where lintcheck should read the sources from"), .help("set the path for a crates.toml where lintcheck should read the sources from"),
)
.arg(
Arg::with_name("threads")
.takes_value(true)
.value_name("N")
.short("j")
.long("jobs")
.help("number of threads to use, 0 automatic choice"),
); );
let app = App::new("Clippy developer tooling") let app = App::new("Clippy developer tooling")