Skip to content

Add multi-threading support for LLVM profile merging#1394

Open
asthetik wants to merge 2 commits intomozilla:masterfrom
asthetik:master
Open

Add multi-threading support for LLVM profile merging#1394
asthetik wants to merge 2 commits intomozilla:masterfrom
asthetik:master

Conversation

@asthetik
Copy link

This PR fixes issue #1116 by passing the --threads parameter from grcov to the underlying llvm-profdata merge command

@marco-c
Copy link
Collaborator

marco-c commented Sep 8, 2025

A couple of things:

  1. we should do the same for llvm-cov export;
  2. since llvm-cov and llvm-profdata actually do this by default when --num-threads is 0 (and they autodetect the right number of threads to use), if the grcov parameter is not passed explicitly by the user, let's rely on their autodetection instead of ours.

When user doesn't pass --threads flag, avoid forcing --num-threads on llvm-profdata and llvm-cov to allow them to auto-detect optimal thread count.
Only pass --num-threads when user explicitly sets a value.
@asthetik
Copy link
Author

asthetik commented Feb 8, 2026

Hi @marco-c , I have updated the changes you mentioned, thanks.

guess_directory: bool,
binary_path: Option<&Path>,
ignore_parsing_error: bool,
llvm_threads: Option<usize>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call this num_threads

Comment on lines +96 to +102
let num_threads_str: String;
// Only pass --num-threads if explicitly specified by the user
if let Some(num) = num_threads {
num_threads_str = num.to_string();
args.push("--num-threads".as_ref());
args.push(num_threads_str.as_ref());
}
Copy link
Collaborator

@marco-c marco-c Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you refactor this to be nicer?
Something like the following might work:

if let Some(num) = num_threads {
    args.push("--num-threads".to_string());
    args.push(num.to_string());
}

guess_directory,
binary_path.as_deref(),
ignore_parsing_error,
llvm_threads,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pass opt.threads and avoid defining an intermediate variable

@marco-c
Copy link
Collaborator

marco-c commented Feb 27, 2026

Could you also add a test for this?

@asthetik
Copy link
Author

Could you also add a test for this?

yes, I will add a new test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

grcov --threads parameter is not passed to sub commands

2 participants