Skip to content

perf: Avoid iterating over already processed files with gcov #611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
39 changes: 34 additions & 5 deletions R/compiled.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,56 @@ run_gcov <- function(path, quiet = TRUE, clean = TRUE,
return()
}

gcov_inputs <- list.files(path, pattern = rex::rex(".gcno", end), recursive = TRUE, full.names = TRUE)
withr::local_dir(src_path)

gcov_inputs <- list.files(".", pattern = rex::rex(".gcno", end), recursive = TRUE, full.names = TRUE)

if (!nzchar(gcov_path)) {
if (length(gcov_inputs)) stop('gcov not found')
return()
}

run_gcov_one <- function(src) {
system_check(gcov_path,
args = c(gcov_args, src, "-p", "-o", dirname(src)),
quiet = quiet, echo = !quiet)
gcov_outputs <- list.files(path, pattern = rex::rex(".gcov", end), recursive = TRUE, full.names = TRUE)
gcov_outputs <- list.files(".", pattern = rex::rex(".gcov", end), recursive = TRUE, full.names = TRUE)

if (!quiet) {
writeLines(paste0("gcov output for ", src, ":"))
writeLines(gcov_outputs)
}

if (clean) {
on.exit(unlink(gcov_outputs))
} else {
gcov_output_base <- file.path("..", "covr", src)
gcov_output_targets <- sub(".", gcov_output_base, gcov_outputs)

if (!quiet) {
writeLines(paste0("gcov output targets for ", src, ":"))
writeLines(gcov_output_targets)
}

lapply(
unique(dirname(gcov_output_targets)),
function(.x) dir.create(.x, recursive = TRUE, showWarnings = FALSE)
)

on.exit({
writeLines(c("Moving gcov outputs to covr directory.", ""))
Copy link
Member

Choose a reason for hiding this comment

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

This is I guess missing a quiet conditional. Also we should probably use the equivalent cli function for the debugging output statements rather than writeLines, we already have a cli dependency anyway.

file.rename(gcov_outputs, gcov_output_targets)
})
}

unlist(lapply(gcov_outputs, parse_gcov, package_path = c(path, getOption("covr.gcov_additional_paths", NULL))), recursive = FALSE)
}

res <- withr::with_dir(src_path, {
compact(unlist(lapply(gcov_inputs, run_gcov_one), recursive = FALSE))
})
res <- compact(unlist(lapply(gcov_inputs, run_gcov_one), recursive = FALSE))

if (!length(res) && length(gcov_inputs))
warning('parsed gcov output was empty')

res
}

Expand Down
Loading