Skip to content

Commit

Permalink
Use doubles instead of integers (#166)
Browse files Browse the repository at this point in the history
Fixes #114
  • Loading branch information
hadley authored Aug 22, 2024
1 parent 7ceecd6 commit f49540d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# profvis (development version)

* `profvis()` now uses doubles instead of integers (#114).
* The version of jQuery bundled in profvis has been upgraded to 3.7.1 (@hedsnz, #139).
* profvis no longer requires purrr or stringr, and no longer suggests ggplot2, devtools, knitr, or rmarkdown.
* `profvis()` now uses elapsed time where possible (#72).
Expand Down
8 changes: 4 additions & 4 deletions R/parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ parse_rprof_lines <- function(lines, expr_source = NULL) {
label_lines <- lines[is_label]
label_pieces <- split_in_half(label_lines, ": ", fixed = TRUE)
labels <- data.frame(
label = as.integer(sub("^#File ", "", label_pieces[, 1])),
label = as.numeric(sub("^#File ", "", label_pieces[, 1])),
path = label_pieces[, 2],
stringsAsFactors = FALSE
)
Expand Down Expand Up @@ -84,7 +84,7 @@ parse_rprof_lines <- function(lines, expr_source = NULL) {
# confusing to users. For instance, profiling profvis::pause(1) can yield
# several hundred MB due to busy waits of pause that trigger significant
# creation of expressions that is not enterily useful to the end user.
memalloc <- sum(as.integer(mem[1:2])) / 1024 ^ 2
memalloc <- sum(as.numeric(mem[1:2])) / 1024 ^ 2

# get_current_mem provides the results as either R_SmallVallocSize or R_LargeVallocSize
# which are internal untis of allocation.
Expand Down Expand Up @@ -158,8 +158,8 @@ parse_rprof_lines <- function(lines, expr_source = NULL) {

# Get file and line numbers
ref_strs <- sub('^,', '', ref_strs)
filenum <- as.integer(sub('#.*', '', ref_strs))
linenum <- as.integer(sub('.*#', '', ref_strs))
filenum <- as.numeric(sub('#.*', '', ref_strs))
linenum <- as.numeric(sub('.*#', '', ref_strs))

nrows <- length(labels)
# Return what is essentially a data frame, but in list format because R is
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ test_that("parsing prof files", {
expect_identical(p$prof$time, c(1L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 5L))
expect_identical(p$prof$depth, c(1L, 2L, 1L, 3L, 2L, 1L, 2L, 1L, 1L))
expect_identical(p$prof$label, c("test space", "line 2", "test", "<GC>", "line 2", "test", "<GC>", "test", ":"))
expect_identical(p$prof$filenum, c(1L, 1L, 1L, NA, 1L, 1L, NA, 1L, NA))
expect_identical(p$prof$linenum, c(1L, 2L, 1L, NA, 2L, 1L, NA, 1L, NA))
expect_identical(p$prof$filenum, c(1, 1, 1, NA, 1, 1, NA, 1, NA))
expect_identical(p$prof$linenum, c(1, 2, 1, NA, 2, 1, NA, 1, NA))
# Memory sizes in the test-parse.prof file were chosen to create these values
expect_identical(p$prof$memalloc, c(136, 152, 152, 168, 168, 168, 152, 152, 152))
expect_identical(p$prof$meminc, c(0, 16, 0, 16, 0, 0, -16, 0, 0))
Expand Down

0 comments on commit f49540d

Please sign in to comment.