Skip to content

r-prof/jointprof

Repository files navigation

jointprof

Travis build status Coverage status CRAN status

The goal of jointprof is to assist profiling R packages that include native code (C++, C, Fortran, ...). It collects profiling output simultaneously using Rprof and gperftools and provides a unified view of profiling data.

See the guide for a more detailed overview, or take a look at the internals document if you're curious.

Installation

Ubuntu

Other Linux distributions may work if you install the right system dependencies (let me know which!).

  1. Install system dependencies:

    sudo apt install \
      libgoogle-perftools-dev \
      libprotoc-dev libprotobuf-dev protobuf-compiler \
      golang-go \
      graphviz
  2. Install pprof:

    go get github.com/google/pprof
  3. Install the package:

    # install.packages("remotes")
    remotes::install_github("r-prof/jointprof")

OS X

  1. Install system dependencies:

    brew install graphviz
  2. Install gperftools (currently from a branch, pull request pending):

    git clone https://github.com/krlmlr/gperftools.git -b f-export-stack
    cd gperftools
    ./autogen.sh
    ./configure
    make
    sudo make install
    cd ..
  3. Install pprof:

    go get github.com/google/pprof
  4. Install the package:

    # install.packages("remotes")
    remotes::install_github("r-prof/jointprof")

Other OS

Windows and Solaris are not supported.

Usage

library(jointprof)

target_file <- "Rprof.out"

# Collect profile data
start_profiler(target_file)
## code to be profiled
stop_profiler()

# Analyze profile data
summaryRprof(target_file)
profvis::profvis(prof_input = target_file)
proftools::readProfileData(target_file)
prof.tree::prof.tree(target_file)

# Convert to pprof format and analyze
pprof_target_file <- "Rprof.pb.gz"
profile_data <- profile::read_rprof(target_file)
profile::write_rprof(profile_data, pprof_target_file)
system2(
  find_pprof(),
  c(
    "-http",
    "localhost:8080",
    shQuote(pprof_target_file)
  )
)

Acknowledgment

This project is being realized with financial support from the