Reads and parses an Rprofmem log file that was created by utils::Rprofmem().

readRprofmem(pathname, as = c("Rprofmem", "fixed", "raw"), drop = 0L, ...)

Arguments

pathname

The Rprofmem log file to be read.

as

Specifies in what format data should be returned. If "raw", the line content of the file is returned as is (as a character vector). If "fixed", as "raw" but with missing newlines added to lines with empty stack calls that may be introduced in R (< 3.5.0) (see Ref. 1). If "Rprofmem", the collected Rprofmem data is fully parsed into bytes and call stack information.

drop

Number of levels to drop from the top of the call stack.

...

Not used

Value

An Rprofmem data.frame or a character vector (if as is "raw" or "fixed"). An Rprofmem data.frame has columns what, bytes, and trace, with:

  • what: (character) type of memory event; either "alloc" or "new page"

  • bytes: (numeric) number of bytes allocated or NA_real_ (when what is "new page")

  • trace: (list of character vectors) zero or more function names

Examples

file <- system.file("extdata", "example.Rprofmem.out", package = "profmem")

raw <- readRprofmem(file, as = "raw")
cat(raw, sep = "\n")
#> new page:
#> 4048 :"integer" 
#> 80048 :"rnorm" "matrix" 
#> 2552 :"rnorm" "matrix" 
#> 80048 :"matrix" 

profmem <- readRprofmem(file, as = "Rprofmem")
print(profmem)
#> Memory allocations:
#> Number of 'new page' entries not displayed: 1
#>        what  bytes               calls
#> 2     alloc   4048           integer()
#> 3     alloc  80048 matrix() -> rnorm()
#> 4     alloc   2552 matrix() -> rnorm()
#> 5     alloc  80048            matrix()
#> total       166696