Rprofseparate from the memory profiler
Rprofhas an option
TRUEthe profiler also writes out information the small and large vector heap sizes, memory in nodes, and number of calls to
Rf_duplicatein the interval.
summaryRprofnow has options to summarize this information. This is available only on Unix at the moment.
--enable-memory-profiling, the function
tracememmarks an object so that a stack trace will be printed when the object is duplicated, or when it is copied by coercion or arithmetic functions. This is intended for tracking accidental copying of large objects.
untracememwill untrace an object (though not all copies of it) and
tracingStatecontrols whether tracing information is printed. In the example below we see that
lmdoes not duplicate its
dataargument, but that
glmdoes, and that
lmdoes copy the response vector.
> data(trees) > tracemem(trees)  "<0x8bfff28>" > lm(log(Volume)~log(Height)+log(Girth),data=trees) Call: lm(formula = log(Volume) ~ log(Height) + log(Girth), data = trees) Coefficients: (Intercept) log(Height) log(Girth) -6.632 1.117 1.983 > glm(log(Volume)~log(Height)+log(Girth),data=trees) memtrace[0x8bfff28->0x8b6d820]: glm memtrace[0x8b6d820->0x89b4c10]: glm Call: glm(formula = log(Volume) ~ log(Height) + log(Girth), data = trees) Coefficients: (Intercept) log(Height) log(Girth) -6.632 1.117 1.983 Degrees of Freedom: 30 Total (i.e. Null); 28 Residual Null Deviance: 8.309 Residual Deviance: 0.1855 AIC: -62.71 > tracemem(trees$Volume)  "<0x895e230>" > lm(Volume~Height+Girth,data=trees) memtrace[0x895e230->0x87a2898]: eval eval model.frame.default model.frame eval eval lm Call: lm(formula = Volume ~ Height + Girth, data = trees) Coefficients: (Intercept) Height Girth -57.9877 0.3393 4.7082
tracememcannot be used on functions, since it uses the same trace bit that
traceuses, and will not work on objects such as environments that are passed by reference and not duplicated. The output for this could be made prettier and sent to a file: the main thing to decide is how to handle files when multiple objects may be being traced.
Rprofmemstarts and stops a pure memory use profiler. A stack trace is sent to an output file on any large enough vector allocation (threshold set by the user) or when
GetNewPageis called to expand the R heap. This profiler does not use timers and so can coexist with other forms of profiling. I do not yet have tools to summarize the output.