Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ pub fn consumer(
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

) {
let mut gcov_type = GcovType::Unknown;

Expand Down Expand Up @@ -290,6 +291,7 @@ pub fn consumer(
profraw_paths.as_slice(),
binary_path.as_ref().unwrap(),
working_dir,
llvm_threads,
) {
Ok(lcovs) => {
let mut new_results: Vec<(String, CovResult)> = Vec::new();
Expand Down
29 changes: 26 additions & 3 deletions src/llvm_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,25 @@ pub fn llvm_profiles_to_lcov(
profile_paths: &[PathBuf],
binary_path: &Path,
working_dir: &Path,
num_threads: Option<usize>,
) -> Result<Vec<Vec<u8>>, String> {
let profdata_path = working_dir.join("grcov.profdata");

let args = vec![
let mut args = vec![
"merge".as_ref(),
"-f".as_ref(),
"-".as_ref(),
"-sparse".as_ref(),
"-o".as_ref(),
profdata_path.as_ref(),
];
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());
}
Comment on lines +96 to +102
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());
}


let stdin_paths: String = profile_paths.iter().fold("".into(), |mut a, x| {
a.push_str(x.to_string_lossy().as_ref());
Expand All @@ -107,14 +115,21 @@ pub fn llvm_profiles_to_lcov(
let results = binaries
.into_par_iter()
.filter_map(|binary| {
let args = [
let mut args = vec![
"export".as_ref(),
binary.as_ref(),
"--instr-profile".as_ref(),
profdata_path.as_ref(),
"--format".as_ref(),
"lcov".as_ref(),
];
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());
}

match run(&cov_tool_path, &args) {
Ok(result) => Some(result),
Expand Down Expand Up @@ -301,6 +316,7 @@ mod tests {
&[tmp_path.join("default.profraw")],
&PathBuf::from("src"), // There is no binary file in src
tmp_path,
None,
);
assert!(lcovs.is_ok());
let lcovs = lcovs.unwrap();
Expand All @@ -317,6 +333,7 @@ mod tests {
&[tmp_path.join("default.profraw")],
&tmp_path.join(binary_path),
tmp_path,
None,
);
assert!(lcovs.is_ok(), "Error: {}", lcovs.unwrap_err());
let lcovs = lcovs.unwrap();
Expand Down Expand Up @@ -349,7 +366,12 @@ mod tests {

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

let lcovs = llvm_profiles_to_lcov(&[profdata_path], &tmp_path.join(binary_path), tmp_path);
let lcovs = llvm_profiles_to_lcov(
&[profdata_path],
&tmp_path.join(binary_path),
tmp_path,
None,
);

assert!(lcovs.is_ok(), "Error: {}", lcovs.unwrap_err());
let lcovs = lcovs.unwrap();
Expand Down Expand Up @@ -396,6 +418,7 @@ mod tests {
&[path_with, path_without],
&tmp_path.join(bin_path),
tmp_path,
None,
);

assert!(lcovs.is_ok(), "Error: {}", lcovs.unwrap_err());
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ fn main() {
let branch_enabled = opt.branch;
let guess_directory = opt.guess_directory;
let ignore_parsing_error = opt.ignore_parsing_error;
let llvm_threads = opt.threads;

let t = thread::Builder::new()
.name(format!("Consumer {i}"))
Expand All @@ -465,6 +466,7 @@ fn main() {
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

);
})
.unwrap();
Expand Down
Loading