Skip to content

Commit 87fefc3

Browse files
committed
Add multi-threading support for LLVM profile merging
1 parent 743a0b9 commit 87fefc3

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ pub fn consumer(
179179
guess_directory: bool,
180180
binary_path: Option<&Path>,
181181
ignore_parsing_error: bool,
182+
num_threads: usize,
182183
) {
183184
let mut gcov_type = GcovType::Unknown;
184185

@@ -290,6 +291,7 @@ pub fn consumer(
290291
profraw_paths.as_slice(),
291292
binary_path.as_ref().unwrap(),
292293
working_dir,
294+
num_threads,
293295
) {
294296
Ok(lcovs) => {
295297
let mut new_results: Vec<(String, CovResult)> = Vec::new();

src/llvm_tools.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,20 @@ pub fn llvm_profiles_to_lcov(
8181
profile_paths: &[PathBuf],
8282
binary_path: &Path,
8383
working_dir: &Path,
84+
num_threads: usize,
8485
) -> Result<Vec<Vec<u8>>, String> {
8586
let profdata_path = working_dir.join("grcov.profdata");
8687

88+
let num_threads = num_threads.to_string();
8789
let args = vec![
8890
"merge".as_ref(),
8991
"-f".as_ref(),
9092
"-".as_ref(),
9193
"-sparse".as_ref(),
9294
"-o".as_ref(),
9395
profdata_path.as_ref(),
96+
"--num-threads".as_ref(),
97+
num_threads.as_ref(),
9498
];
9599

96100
let stdin_paths: String = profile_paths.iter().fold("".into(), |mut a, x| {
@@ -301,6 +305,7 @@ mod tests {
301305
&[tmp_path.join("default.profraw")],
302306
&PathBuf::from("src"), // There is no binary file in src
303307
tmp_path,
308+
1,
304309
);
305310
assert!(lcovs.is_ok());
306311
let lcovs = lcovs.unwrap();
@@ -317,6 +322,7 @@ mod tests {
317322
&[tmp_path.join("default.profraw")],
318323
&tmp_path.join(binary_path),
319324
tmp_path,
325+
1,
320326
);
321327
assert!(lcovs.is_ok(), "Error: {}", lcovs.unwrap_err());
322328
let lcovs = lcovs.unwrap();
@@ -349,7 +355,8 @@ mod tests {
349355

350356
assert_eq!(status.unwrap().code().unwrap(), 0);
351357

352-
let lcovs = llvm_profiles_to_lcov(&[profdata_path], &tmp_path.join(binary_path), tmp_path);
358+
let lcovs =
359+
llvm_profiles_to_lcov(&[profdata_path], &tmp_path.join(binary_path), tmp_path, 1);
353360

354361
assert!(lcovs.is_ok(), "Error: {}", lcovs.unwrap_err());
355362
let lcovs = lcovs.unwrap();
@@ -396,6 +403,7 @@ mod tests {
396403
&[path_with, path_without],
397404
&tmp_path.join(bin_path),
398405
tmp_path,
406+
1,
399407
);
400408

401409
assert!(lcovs.is_ok(), "Error: {}", lcovs.unwrap_err());

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ fn main() {
465465
guess_directory,
466466
binary_path.as_deref(),
467467
ignore_parsing_error,
468+
num_threads,
468469
);
469470
})
470471
.unwrap();

0 commit comments

Comments
 (0)