summaryRprof {utils} | R Documentation |
Summarise the output of the Rprof
function to show the
amount of time used by different R functions.
summaryRprof(filename = "Rprof.out", chunksize = 5000, memory = c("none", "both", "tseries", "stats"), lines = c("hide", "show", "both"), index = 2, diff = TRUE, exclude = NULL, basenames = 1)
filename |
Name of a file produced by |
chunksize |
Number of lines to read at a time. |
memory |
Summaries for memory information. See ‘Memory profiling’ below. Can be abbreviated. |
lines |
Summaries for line information. See ‘Line profiling’ below. Can be abbreviated. |
index |
How to summarize the stack trace for memory information. See ‘Details’ below. |
diff |
If |
exclude |
Functions to exclude when summarizing the stack trace for memory summaries. |
basenames |
Number of components of the path to filenames to display. |
This function provides the analysis code for Rprof
files
used by R CMD Rprof
.
As the profiling output file could be larger than available memory, it
is read in blocks of chunksize
lines. Increasing chunksize
will make the function run faster if sufficient memory is available.
If memory = "none"
and lines = "hide"
, a list with components
by.self |
A data frame of timings sorted by ‘self’ time. |
by.total |
A data frame of timings sorted by ‘total’ time. |
sample.interval |
The sampling interval. |
sampling.time |
Total time of profiling run. |
The first two components have columns self.time, self.pct, total.time and total.pct, the times in seconds and percentages of the total time spent executing code in that function and code in that function or called from that function, respectively.
If lines = "show"
, an additional component is added to the list:
by.line |
A data frame of timings sorted by source location. |
If memory = "both"
the same list but with memory consumption in Mb
in addition to the timings.
If memory = "tseries"
a data frame giving memory statistics over
time. Memory usage is in bytes.
If memory = "stats"
a by
object giving memory statistics
by function. Memory usage is in bytes.
If no events were recorded, a zero-row data frame is returned.
Options other than memory = "none"
apply only to files produced
by Rprof(memory.profiling = TRUE)
.
When called with memory.profiling = TRUE
, the profiler writes
information on three aspects of memory use: vector memory in small
blocks on the R heap, vector memory in large blocks (from
malloc
), memory in nodes on the R heap. It also records the number of
calls to the internal function duplicate
in the time
interval. duplicate
is called by C code when arguments need to be
copied. Note that the profiler does not track which function actually
allocated the memory.
With memory = "both"
the change in total memory (truncated at zero)
is reported in addition to timing data.
With memory = "tseries"
or memory = "stats"
the index
argument specifies how to summarize the stack trace. A positive number
specifies that many calls from the bottom of the stack; a negative
number specifies the number of calls from the top of the stack. With
memory = "tseries"
the index is used to construct labels and may be
a vector to give multiple sets of labels. With memory = "stats"
the
index must be a single number and specifies how to aggregate the data to
the maximum and average of the memory statistics. With both
memory = "tseries"
and memory = "stats"
the argument
diff = TRUE
asks for summaries of the increase in memory use over
the sampling interval and diff = FALSE
asks for the memory use at
the end of the interval.
If the code being run has source reference information retained (via
keep.source = TRUE
in source
or
KeepSource = TRUE
in a package ‘DESCRIPTION’ file or
some other way), then information about the origin of lines is
recorded during profiling. By default this is not displayed, but
the lines
parameter can enable the display.
If lines = "show"
, line locations will be used in preference
to the usual function name information, and the results
will be displayed ordered by location in addition to the other orderings.
If lines = "both"
, line locations will be mixed with function
names in a combined display.
The chapter on “Tidying and profiling R code” in “Writing R Extensions” (see the ‘doc/manual’ subdirectory of the R source tree).
tracemem
traces copying of an object via the C function
duplicate
.
Rprofmem
is a non-sampling memory-use profiler.
https://developer.r-project.org/memory-profiling.html
## Not run: ## Rprof() is not available on all platforms Rprof(tmp <- tempfile()) example(glm) Rprof() summaryRprof(tmp) unlink(tmp) ## End(Not run)