Skip to content

Commit

Permalink
Add simplify argument to simplify profiles on R 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Jun 26, 2020
1 parent 2ae0c5e commit 24bcecc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
profvis 0.3.6.9000
=============

* Added `simplify` argument. When `TRUE` (the default), the profiles are simplified using the new `filter.callframes` argument of R 4.0. This argument has no effect on older R versions.

* Fixed [#111](https://github.com/rstudio/profvis/issues/111): auto-scrolling to lines of code did not work in some browsers. ([#113](https://github.com/rstudio/profvis/pull/113))

profvis 0.3.6
Expand Down
17 changes: 14 additions & 3 deletions R/profvis.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
#' \code{torture = steps} helps prevent this, by making R trigger garbage
#' collection after every \code{torture} memory allocation step.
#'
#' @param simplify Whether to simplify the profiles by removing
#' intervening frames caused by lazy evaluation. This only has an
#' effect on R 4.0. See the \code{filter.callframes} argument of
#' \code{\link{Rprof}()}.
#'
#' @seealso \code{\link{print.profvis}} for printing options.
#' @seealso \code{\link{Rprof}} for more information about how the profiling
#' data is collected.
Expand Down Expand Up @@ -75,7 +80,7 @@
#' @export
profvis <- function(expr = NULL, interval = 0.01, prof_output = NULL,
prof_input = NULL, width = NULL, height = NULL,
split = c("h", "v"), torture = 0)
split = c("h", "v"), torture = 0, simplify = TRUE)
{
split <- match.arg(split)
expr_q <- substitute(expr)
Expand Down Expand Up @@ -128,8 +133,14 @@ profvis <- function(expr = NULL, interval = 0.01, prof_output = NULL,
on.exit(gctorture2(step = 0), add = TRUE)
}

Rprof(prof_output, interval = interval, line.profiling = TRUE,
gc.profiling = TRUE, memory.profiling = TRUE)
if (getRversion() >= "4.0.0") {
Rprof(prof_output, interval = interval, line.profiling = TRUE,
gc.profiling = TRUE, memory.profiling = TRUE,
filter.callframes = simplify)
} else {
Rprof(prof_output, interval = interval, line.profiling = TRUE,
gc.profiling = TRUE, memory.profiling = TRUE)
}
on.exit(Rprof(NULL), add = TRUE)
if (remove_on_exit)
on.exit(unlink(prof_output), add = TRUE)
Expand Down
8 changes: 7 additions & 1 deletion man/profvis.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 24bcecc

Please sign in to comment.