diff --git a/DESCRIPTION b/DESCRIPTION index 1a89c17..ff626ab 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,13 +1,13 @@ Package: syrup Title: Measure Memory and CPU Usage for Parallel R Code -Version: 0.0.0.9000 +Version: 0.1.0 Authors@R: c( person("Simon", "Couch", , "simon.couch@posit.co", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5676-5107")), person(given = "Posit Software, PBC", role = c("cph", "fnd")) ) Description: Measures memory and CPU usage of R code by regularly taking - snapshots of calls to the system command ps. The package provides an entry + snapshots of calls to the system command 'ps'. The package provides an entry point (albeit coarse) to profile usage of system resources by R code run in parallel. License: MIT + file LICENSE diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..71848c4 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,3 @@ +# syrup 0.1.0 + +* Initial CRAN submission. diff --git a/R/syrup.R b/R/syrup.R index 7dba714..0d432c5 100644 --- a/R/syrup.R +++ b/R/syrup.R @@ -120,17 +120,12 @@ syrup <- function(expr, interval = .5, peak = FALSE, env = caller_env()) { # tell `sesh` to stop taking snapshots file.remove(keep_going_file) - Sys.sleep(interval + .1) + Sys.sleep(interval + .2) - # grab the result from sesh and close it - sesh_res <- sesh$read() - sesh$close() + res <- retrieve_results(sesh) withr::deferred_clear() - # return the memory usage information - res <- sesh_res$result - if (identical(res$id[length(res$id)], 1) && !isTRUE(peak)) { rlang::warn(c( "!" = "`expr` evaluated fully before syrup could take a snapshot of memory usage.", diff --git a/R/utils.R b/R/utils.R index f2a8555..d6a17f6 100644 --- a/R/utils.R +++ b/R/utils.R @@ -40,3 +40,28 @@ calculate_pct_cpu <- function(time, user, system) { c(NA_real_, (user_diffs + system_diffs) * 100 / intervals) } + +# grab the result from sesh and close it. +# may be a slightly longer delay before sesh is able to return, so iteratively +# query until we get a result back. +retrieve_results <- function(sesh, call = caller_env()) { + sesh_res <- sesh$read() + cnt <- 1 + while (is.null(sesh_res) & cnt < 10) { + Sys.sleep(.2) + sesh_res <- sesh$read() + cnt <- cnt + 1 + } + + sesh$close() + + if (cnt == 10) { + rlang::abort( + "Unable to retrieve resource usage results from the temporary session.", + .internal = TRUE, + call = call + ) + } + + sesh_res$result +} diff --git a/README.Rmd b/README.Rmd index d6750bf..432d4ee 100644 --- a/README.Rmd +++ b/README.Rmd @@ -27,6 +27,12 @@ The package name is an homage to syrupy (**SY**stem **R**esource **U**sage **P** ## Installation +Install the latest release of syrup from CRAN like so: + +``` r +install.packages("syrup") +``` + You can install the development version of syrup like so: ``` r diff --git a/README.md b/README.md index ed67689..6f6ca95 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,12 @@ The package name is an homage to syrupy (**SY**stem **R**esource ## Installation +Install the latest release of syrup from CRAN like so: + +``` r +install.packages("syrup") +``` + You can install the development version of syrup like so: ``` r diff --git a/man/syrup-package.Rd b/man/syrup-package.Rd index c1ec541..8be6435 100644 --- a/man/syrup-package.Rd +++ b/man/syrup-package.Rd @@ -5,7 +5,9 @@ \alias{syrup-package} \title{syrup: Measure Memory and CPU Usage for Parallel R Code} \description{ -Measures memory and CPU usage of R code by regularly taking snapshots of calls to the system command ps. The package provides an entry point (albeit coarse) to profile usage of system resources by R code run in parallel. +\if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} + +Measures memory and CPU usage of R code by regularly taking snapshots of calls to the system command 'ps'. The package provides an entry point (albeit coarse) to profile usage of system resources by R code run in parallel. } \seealso{ Useful links: