Skip to content

Partially aggregated samples of repeated function calls #115

@wlandau

Description

@wlandau

In my use cases, I call a lot of fast functions repeatedly, and flame graphs help me understand how the computation times adds up. I like pprof because the flame graphs fully aggregate the samples of each function. Below, it is easy to see that h() is more of a bottleneck than g().

f <- function(...) {
  file <- tempfile()
  g(file)
  h(file)
  unlink(file)
  invisible()
}

g <- function(file) {
  writeLines("lorem ipsum", file)
}

h <- function(file) {
  digest::digest(file)
}

rprof <- tempfile()
pprof <- tempfile()
Rprof(filename = rprof)
replicate(1e3, f())
Rprof(NULL)
samples <- profile::read_rprof(rprof)
profile::write_pprof(samples, pprof)
system2(
  "/home/landau/go/bin/pprof",
  c("-http", "0.0.0.0:8080", pprof)
)

Screenshot_20191126_163811

I want to use profvis instead of pprof because it is much easier to install and use, but the flame graphs only partially aggregate the samples, which makes interpretation more difficult. Below, g() and h() appear in multiple places, so I cannot tell which one is more of a bottleneck.

packageDescription("profvis")$GithubSHA1
#> [1] "51b0671d65ac4329eef989ca36121f13c5f87c8c"
  
f <- function(...) {
  file <- tempfile()
  g(file)
  h(file)
  unlink(file)
  invisible()
}

g <- function(file) {
  writeLines("lorem ipsum", file)
}

h <- function(file) {
  digest::digest(file)
}

profvis::profvis(replicate(1e3, f()))

Created on 2019-11-26 by the reprex package (v0.3.0)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions