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:
@@ -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;
|
||||||
println!(
|
|
||||||
"{}/{} {}% Linting {} {} in target dir {:?}",
|
if thread_limit == 1 {
|
||||||
index, total_crates_to_lint, perc, &self.name, &self.version, target_dir_index
|
println!(
|
||||||
);
|
"{}/{} {}% Linting {} {}",
|
||||||
|
index, total_crates_to_lint, perc, &self.name, &self.version
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
println!(
|
||||||
|
"{}/{} {}% Linting {} {} in target dir {:?}",
|
||||||
|
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
|
||||||
|
|
||||||
// Rayon seems to return thread count so half that for core count
|
// by default, use a single thread
|
||||||
let num_cpus: usize = rayon::current_num_threads() / 2;
|
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::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();
|
||||||
|
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|||||||
Reference in New Issue
Block a user