Skip to content

Commit

Permalink
Parallelize llvm-cov invocations (#1015)
Browse files Browse the repository at this point in the history
llvm-cov can be fairly slow per invocation, but can safely and easily be
parallelized for significant speed-ups when there are many binary
artifacts.

See #1013.
  • Loading branch information
jonhoo committed Apr 12, 2023
1 parent 917494a commit cd39af5
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/llvm_tools.rs
@@ -1,5 +1,6 @@
use cargo_binutils::Tool;
use once_cell::sync::OnceCell;
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
use std::env::consts::EXE_SUFFIX;
use std::ffi::OsStr;
use std::fs;
Expand Down Expand Up @@ -116,27 +117,31 @@ pub fn profraws_to_lcov(
paths
};

let mut results = vec![];
let cov_tool_path = get_cov_path()?;

for binary in binaries {
let args = [
"export".as_ref(),
binary.as_ref(),
"--instr-profile".as_ref(),
profdata_path.as_ref(),
"--format".as_ref(),
"lcov".as_ref(),
];

match run(&cov_tool_path, &args) {
Ok(result) => results.push(result),
Err(err_str) => warn!(
"Suppressing error returned by llvm-cov tool for binary {:?}\n{}",
binary, err_str
),
}
}
let results = binaries
.into_par_iter()
.filter_map(|binary| {
let args = [
"export".as_ref(),
binary.as_ref(),
"--instr-profile".as_ref(),
profdata_path.as_ref(),
"--format".as_ref(),
"lcov".as_ref(),
];

match run(&cov_tool_path, &args) {
Ok(result) => Some(result),
Err(err_str) => {
warn!(
"Suppressing error returned by llvm-cov tool for binary {:?}\n{}",
binary, err_str
);
None
}
}
})
.collect::<Vec<_>>();

Ok(results)
}
Expand Down

0 comments on commit cd39af5

Please sign in to comment.