Run R code and display profiling results in a local interactive pprof server. Results are collected with record_pprof().

pprof(
  expr,
  seconds_timeout = Inf,
  host = "localhost",
  port = proffer::random_port(),
  browse = interactive(),
  verbose = TRUE,
  ...
)

Arguments

expr

R code to run and profile.

seconds_timeout

Maximum number of seconds of elapsed time to profile expr. When the timeout is reached, proffer stops running expr and returns the profiling samples taken during the seconds_timeout time window.

host

Host name. Set to "localhost" to view locally or "0.0.0.0" to view from another machine. If you view from another machine, the printed out URL will not be valid. For example, if pprof() or serve_pprof() prints "http://0.0.0.0:8080", then you need to replace 0.0.0.0 with your computer's name or IP address, e.g. "http://my_computer.com:8080".

port

Port number for hosting the local pprof server. Chosen randomly by default.

browse

Logical, whether to open a browser to view the pprof server.

verbose

Logical, whether to print console messages such as the URL of the local pprof server.

...

Additional arguments passed on to Rprof() via record_pprof().

Value

A processx::process$new() handle. Use this handle to take down the server with $kill().

Examples

if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) {
# Start a pprof virtual server in the background.
px <- pprof(replicate(1e2, sample.int(1e4)))
# Terminate the server.
px$kill()
}