Skip to content

Commit

Permalink
Reduce check time of examples
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Jun 28, 2021
1 parent a7b0859 commit afbbf3a
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: proffer
Title: Profile R Code and Visualize with 'Pprof'
Version: 0.1.2.9000
Version: 0.1.3
Encoding: UTF-8
Language: en-US
License: MIT + file LICENSE
Expand Down
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# proffer 0.1.2.9000

# proffer 0.1.3

* Reduce check time of examples.

# proffer 0.1.2

Expand Down
2 changes: 1 addition & 1 deletion R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#' @importFrom utils browseURL Rprof
#' @importFrom withr with_path
#' @examples
#' \dontrun{
#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) {
#' # Start a pprof virtual server in the background.
#' px <- pprof(replicate(1e2, sample.int(1e4)))
#' # Terminate the server.
Expand Down
2 changes: 1 addition & 1 deletion R/path.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' for setup instructions.
#' @return Character, path to `pprof` it exists and `""` otherwise.
#' @examples
#' \dontrun{
#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) {
#' pprof_path()
#' }
pprof_path <- function() {
Expand Down
10 changes: 6 additions & 4 deletions R/pprof.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' for setup instructions.
#' @inheritParams pprof
#' @examples
#' \dontrun{
#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) {
#' test_pprof()
#' }
test_pprof <- function(
Expand Down Expand Up @@ -45,7 +45,7 @@ test_pprof <- function(
#' @param ... Additional arguments passed on to [Rprof()]
#' via [record_pprof()].
#' @examples
#' \dontrun{
#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) {
#' # Start a pprof virtual server in the background.
#' px <- pprof(replicate(1e2, sample.int(1e4)))
#' # Terminate the server.
Expand Down Expand Up @@ -82,7 +82,7 @@ pprof <- function(
#' @param rprof Path to profiling samples generated
#' by `Rprof()` or [record_rprof()].
#' @examples
#' \dontrun{
#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) {
#' rprof <- record_rprof(replicate(1e2, sample.int(1e4)))
#' # Start a pprof virtual server in the background.
#' px <- serve_rprof(rprof)
Expand Down Expand Up @@ -129,7 +129,7 @@ serve_rprof <- function(
#' @param verbose Logical, whether to print console messages
#' such as the URL of the local `pprof` server.
#' @examples
#' \dontrun{
#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) {
#' pprof <- record_pprof(replicate(1e2, sample.int(1e4)))
#' # Start a pprof virtual server in the background.
#' px <- serve_pprof(pprof)
Expand Down Expand Up @@ -162,6 +162,8 @@ serve_pprof <- function(
#' @return Port number, positive integer of length 1.
#' @param lower Integer of length 1, lower bound of the port number.
#' @param upper Integer of length 1, upper bound of the port number.
#' @examples
#' random_port()
random_port <- function(lower = 49152L, upper = 65355L) {
sample(seq.int(from = lower, to = upper, by = 1L), size = 1L)
}
Expand Down
8 changes: 8 additions & 0 deletions R/record.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#' @param ... Additional arguments passed on to [Rprof()]
#' via [record_rprof()].
#' @examples
#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) {
#' # Returns a path to pprof samples.
#' record_pprof(replicate(1e2, sample.int(1e4)))
#' }
record_pprof <- function(expr, pprof = tempfile(), ...) {
rprof <- record_rprof(expr, ...)
to_pprof(rprof, pprof = pprof)
Expand All @@ -27,8 +29,10 @@ record_pprof <- function(expr, pprof = tempfile(), ...) {
#' Also returned from the function.
#' @param ... Additional arguments passed on to [Rprof()].
#' @examples
#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) {
#' # Returns a path to Rprof samples.
#' record_rprof(replicate(1e2, sample.int(1e4)))
#' }
record_rprof <- function(expr, rprof = tempfile(), ...) {
on.exit(Rprof(NULL))
Rprof(filename = rprof, ...)
Expand All @@ -43,8 +47,10 @@ record_rprof <- function(expr, rprof = tempfile(), ...) {
#' @param rprof Path to Rprof samples.
#' @param pprof Path to pprof samples.
#' @examples
#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) {
#' rprof <- record_rprof(replicate(1e2, sample.int(1e4)))
#' to_pprof(rprof)
#' }
to_pprof <- function(rprof, pprof = tempfile()) {
samples <- profile::read_rprof(path = rprof)
profile::write_pprof(x = samples, path = pprof)
Expand All @@ -58,8 +64,10 @@ to_pprof <- function(rprof, pprof = tempfile()) {
#' @param pprof Path to pprof samples.
#' @param rprof Path to Rprof samples.
#' @examples
#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) {
#' pprof <- record_pprof(replicate(1e2, sample.int(1e4)))
#' to_rprof(pprof)
#' }
to_rprof <- function(pprof, rprof = tempfile()) {
samples <- profile::read_pprof(path = pprof)
profile::write_rprof(x = samples, path = rprof)
Expand Down
2 changes: 1 addition & 1 deletion man/pprof.Rd

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

2 changes: 1 addition & 1 deletion man/pprof_path.Rd

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

2 changes: 1 addition & 1 deletion man/proffer-package.Rd

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

3 changes: 3 additions & 0 deletions man/random_port.Rd

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

2 changes: 2 additions & 0 deletions man/record_pprof.Rd

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

2 changes: 2 additions & 0 deletions man/record_rprof.Rd

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

2 changes: 1 addition & 1 deletion man/serve_pprof.Rd

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

2 changes: 1 addition & 1 deletion man/serve_rprof.Rd

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

2 changes: 1 addition & 1 deletion man/test_pprof.Rd

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

2 changes: 2 additions & 0 deletions man/to_pprof.Rd

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

2 changes: 2 additions & 0 deletions man/to_rprof.Rd

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

0 comments on commit afbbf3a

Please sign in to comment.