R/pprof-read.R

Defines functions read_msg read_pprof

Documented in read_pprof

#' File I/O for profile data
#'
#' @description
#' `read_pprof()` reads a file generated by `pprof -proto`, `write_pprof()`
#' writes a Gzip-compressed file that can be processed with `pprof`.
#'
#' @details
#' Use the \pkg{proftools}, \pkg{profvis}, or \pkg{prof.tree} R packages to
#' further analyze files created by the `write_rprof()` function.
#'
#' @return
#' Valid profile data (readers), input data (writers).
#'
#' @export
#' @rdname read_rprof
#' @include rprof-read.R
read_pprof <- function(path, ..., version = "1.0") {
  stopifnot(version == get_default_meta()$value)
  msg <- read_msg(path)
  ds <- msg_to_ds(msg)
  validate_profile(ds)
  ds
}

read_msg <- function(path) {
  provide_proto()

  con <- gzfile(path, "rb")
  defer(close(con))
  RProtoBuf::read(perftools.profiles.Profile, con)
}

Try the profile package in your browser

Any scripts or data that you put into this service are public.

profile documentation built on Aug. 22, 2022, 9:10 a.m.