diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-02-19 23:20:05 +0100 |
|---|---|---|
| committer | Matthias Krüger <matthias.krueger@famsik.de> | 2021-02-19 23:20:05 +0100 |
| commit | 8499a32859280e3f29a2b000450bcec13bf80b9c (patch) | |
| tree | b880336f4c638178bdbf14d26682798f58fd2698 /clippy_dev | |
| parent | 22aeec09e4375268ff9cbd7057d3b57aac47a2c5 (diff) | |
| download | rust-8499a32859280e3f29a2b000450bcec13bf80b9c.tar.gz rust-8499a32859280e3f29a2b000450bcec13bf80b9c.zip | |
lintcheck: add -j <N> option to configure threads.
defaults to 1 -j 0 choses the number of threads automtically (= number of physical cores)
Diffstat (limited to 'clippy_dev')
| -rw-r--r-- | clippy_dev/src/lintcheck.rs | 36 | ||||
| -rw-r--r-- | clippy_dev/src/main.rs | 8 |
2 files changed, 38 insertions, 6 deletions
diff --git a/clippy_dev/src/lintcheck.rs b/clippy_dev/src/lintcheck.rs index fe2614e2de7..d9933f0963a 100644 --- a/clippy_dev/src/lintcheck.rs +++ b/clippy_dev/src/lintcheck.rs @@ -229,10 +229,19 @@ impl Crate { // "loop" the index within 0..thread_limit let target_dir_index = index % thread_limit; let perc = ((index * 100) as f32 / total_crates_to_lint as f32) as u8; - println!( - "{}/{} {}% Linting {} {} in target dir {:?}", - index, total_crates_to_lint, perc, &self.name, &self.version, target_dir_index - ); + + if thread_limit == 1 { + 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 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 // order to achive some kind of parallelism - // Rayon seems to return thread count so half that for core count - let num_cpus: usize = rayon::current_num_threads() / 2; + // 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::current_num_threads() / 2) as usize + } else { + threads + } + }, + // no -j passed, use a single thread + None => 1, + }; let num_crates = crates.len(); diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs index 5dbd46935a5..505d465760c 100644 --- a/clippy_dev/src/main.rs +++ b/clippy_dev/src/main.rs @@ -69,6 +69,14 @@ fn get_clap_config<'a>() -> ArgMatches<'a> { .value_name("CRATES-SOURCES-TOML-PATH") .long("crates-toml") .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") |
