R Under development (unstable) (2025-05-01 r88184 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library("profmem") > > message("readRprofmem() ...") readRprofmem() ... > > message(" - corrupt file") - corrupt file > > broken <- system.file("extdata", "broken.Rprofmem.out", package = "profmem") > > bfr <- readLines(broken) > cat("readLines(broken):\n") readLines(broken): > print(bfr) [1] "232 :" "472 :" [3] "472 :" "1064 :new page:1040 :\"raw\" " [5] "256 :\"matrix\" " "536 :\"matrix\" " [7] "536 :\"matrix\" " "1064 :\"matrix\" " [9] "840 :\"rnorm\" \"matrix\" " "2544 :\"rnorm\" \"matrix\" " [11] "840 :\"matrix\" " > > raw <- readRprofmem(broken, as = "raw") > cat("readRprofmem(broken, as = 'raw'):\n") readRprofmem(broken, as = 'raw'): > print(raw) [1] "232 :" "472 :" [3] "472 :" "1064 :new page:1040 :\"raw\" " [5] "256 :\"matrix\" " "536 :\"matrix\" " [7] "536 :\"matrix\" " "1064 :\"matrix\" " [9] "840 :\"rnorm\" \"matrix\" " "2544 :\"rnorm\" \"matrix\" " [11] "840 :\"matrix\" " > stopifnot( + length(raw) == length(bfr), + all(raw == bfr) + ) > > message("readRprofmem(broken, as = 'fixed'):\n") readRprofmem(broken, as = 'fixed'): > fixed <- readRprofmem(broken, as = "fixed") > print(fixed) [1] "232 :" "472 :" [3] "472 :" "1064 :" [5] "new page :" "1040 :\"raw\" " [7] "256 :\"matrix\" " "536 :\"matrix\" " [9] "536 :\"matrix\" " "1064 :\"matrix\" " [11] "840 :\"rnorm\" \"matrix\" " "2544 :\"rnorm\" \"matrix\" " [13] "840 :\"matrix\" " > stopifnot(length(fixed) >= length(bfr)) > > p <- readRprofmem(broken, as = "Rprofmem") > cat("readRprofmem(broken, as = 'Rprofmem'):\n") readRprofmem(broken, as = 'Rprofmem'): > print(p) Memory allocations: Number of 'new page' entries not displayed: 1 what bytes calls 1 alloc 232 2 alloc 472 3 alloc 472 4 alloc 1064 6 alloc 1040 raw() 7 alloc 256 matrix() 8 alloc 536 matrix() 9 alloc 536 matrix() 10 alloc 1064 matrix() 11 alloc 840 matrix() -> rnorm() 12 alloc 2544 matrix() -> rnorm() 13 alloc 840 matrix() total 9896 > str(p) Classes 'Rprofmem' and 'data.frame': 13 obs. of 3 variables: $ what : chr "alloc" "alloc" "alloc" "alloc" ... $ bytes: num 232 472 472 1064 NA ... $ trace:List of 13 ..$ : NULL ..$ : NULL ..$ : NULL ..$ : NULL ..$ : NULL ..$ : chr "raw" ..$ : chr "matrix" ..$ : chr "matrix" ..$ : chr "matrix" ..$ : chr "matrix" ..$ : chr "rnorm" "matrix" ..$ : chr "rnorm" "matrix" ..$ : chr "matrix" > stopifnot(nrow(p) == length(fixed)) > > > message(" - empty file") - empty file > > options(profmem.debug = TRUE) > > empty <- tempfile() > writeLines(character(0L), con = empty) > > bfr <- readLines(empty) > stopifnot(length(bfr) == 0) > > raw <- readRprofmem(empty, as = "raw") > stopifnot(is.character(raw), length(raw) == 0) > > fixed <- readRprofmem(empty, as = "fixed") > stopifnot(is.character(raw), length(raw) == 0) > > p <- readRprofmem(empty, as = "Rprofmem") character(0) > stopifnot(nrow(p) == 0L) > > options(profmem.debug = FALSE) > > > if (capabilities("profmem")) { + + live <- tempfile() + Rprofmem(live) + x <- raw(1000) + A <- matrix(rnorm(100), ncol=10) + Rprofmem() + + bfr <- readLines(live) + cat("readLines(live):\n") + print(bfr) + + raw <- readRprofmem(live, as = "raw") + cat("readRprofmem(live, as = 'raw'):\n") + print(raw) + stopifnot( + length(raw) == length(bfr), + all(raw == bfr) + ) + + fixed <- readRprofmem(live, as = "fixed") + cat("readRprofmem(live, as = 'fixed'):\n") + print(fixed) + stopifnot(length(fixed) >= length(bfr)) + + p <- readRprofmem(live, as = "Rprofmem") + cat("readRprofmem(live, as = 'Rprofmem'):\n") + print(p) + str(p) + stopifnot(nrow(p) == length(fixed)) + + } ## if (capabilities("profmem")) readLines(live): [1] "256 :" "488 :" [3] "488 :" "1072 :" [5] "1048 :\"raw\" " "272 :\"matrix\" " [7] "552 :\"matrix\" " "552 :\"matrix\" " [9] "1072 :\"matrix\" " "848 :\"rnorm\" \"matrix\" " [11] "2552 :\"rnorm\" \"matrix\" " "848 :\"matrix\" " readRprofmem(live, as = 'raw'): [1] "256 :" "488 :" [3] "488 :" "1072 :" [5] "1048 :\"raw\" " "272 :\"matrix\" " [7] "552 :\"matrix\" " "552 :\"matrix\" " [9] "1072 :\"matrix\" " "848 :\"rnorm\" \"matrix\" " [11] "2552 :\"rnorm\" \"matrix\" " "848 :\"matrix\" " readRprofmem(live, as = 'fixed'): [1] "256 :" "488 :" [3] "488 :" "1072 :" [5] "1048 :\"raw\" " "272 :\"matrix\" " [7] "552 :\"matrix\" " "552 :\"matrix\" " [9] "1072 :\"matrix\" " "848 :\"rnorm\" \"matrix\" " [11] "2552 :\"rnorm\" \"matrix\" " "848 :\"matrix\" " readRprofmem(live, as = 'Rprofmem'): Memory allocations: what bytes calls 1 alloc 256 2 alloc 488 3 alloc 488 4 alloc 1072 5 alloc 1048 raw() 6 alloc 272 matrix() 7 alloc 552 matrix() 8 alloc 552 matrix() 9 alloc 1072 matrix() 10 alloc 848 matrix() -> rnorm() 11 alloc 2552 matrix() -> rnorm() 12 alloc 848 matrix() total 10048 Classes 'Rprofmem' and 'data.frame': 12 obs. of 3 variables: $ what : chr "alloc" "alloc" "alloc" "alloc" ... $ bytes: num 256 488 488 1072 1048 ... $ trace:List of 12 ..$ : NULL ..$ : NULL ..$ : NULL ..$ : NULL ..$ : chr "raw" ..$ : chr "matrix" ..$ : chr "matrix" ..$ : chr "matrix" ..$ : chr "matrix" ..$ : chr "rnorm" "matrix" ..$ : chr "rnorm" "matrix" ..$ : chr "matrix" > > message("readRprofmem() ... DONE") readRprofmem() ... DONE > > > proc.time() user system elapsed 0.17 0.01 0.18