Skip to content

Commit

Permalink
v0.1.0 release candidate (#8)
Browse files Browse the repository at this point in the history
* `usethis::use_news_md()`, update install instructions, single-quote `ps` in description, bump version

* in the release process, resolved:

```
Error in UseMethod("mutate") :
  no applicable method for 'mutate' applied to an object of class "NULL"
Calls: <Anonymous> ... eval -> eval -> syrup -> mutate_pct_cpu -> <Anonymous>"
```

...intermittently for some calls. turns out this was because the session had a longer-than-expected delay before its results were able to be `read()`--just iteratively query with additional delay until we get results.
  • Loading branch information
simonpcouch authored Jul 9, 2024
1 parent 0a8d131 commit c2c76d8
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 10 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", 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
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# syrup 0.1.0

* Initial CRAN submission.
9 changes: 2 additions & 7 deletions R/syrup.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
25 changes: 25 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion man/syrup-package.Rd

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

0 comments on commit c2c76d8

Please sign in to comment.