Skip to content

Commit bba1e3c

Browse files
author
tlumley
committed
mention --enable-memory-profiling configure option
git-svn-id: https://svn.r-project.org/R-dev-web/trunk@1985 c52295ea-58df-0310-926a-d16021944841
1 parent 0fe3b7c commit bba1e3c

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

memory-profiling.html

+10-15
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ <h1 align="center">Memory profiling in R</h1>
2222
the interval. <code>summaryRprof</code> now has options to summarize this information.
2323
This is available only on Unix at the moment.
2424

25-
<li> If R is compiled with <code>R_MEMORY_PROFILING</code> defined, the function <code>tracemem</code> marks an object so that <code>Rf_duplicate</code> will print a stack trace when the object is duplicated. This is intended for tracking accidental copying of large objects. <code>untracemem</code> will untrace an object (though not all copies of it) and <code>tracingState</code> controls whether tracing information is printed. In the example below we see that <code>lm</code> does not duplicate its <code>data</code> argument, but that <code>glm</code> does, and that <code>lm</code> does copy the response vector three times.
25+
<li> If R is compiled with <code>--enable-memory-profiling</code>, the function <code>tracemem</code> marks 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. <code>untracemem</code> will untrace an object (though not all copies of it) and <code>tracingState</code> controls whether tracing information is printed. In the example below we see that <code>lm</code> does not duplicate its <code>data</code> argument, but that <code>glm</code> does, and that <code>lm</code> does copy the response vector.
2626
<pre>
2727
> data(trees)
28-
> ls()
29-
[1] "trees"
3028
> tracemem(trees)
31-
[1] "<0xa499a88>"
29+
[1] "<0x8bfff28>"
3230
> lm(log(Volume)~log(Height)+log(Girth),data=trees)
3331

3432
Call:
@@ -38,9 +36,9 @@ <h1 align="center">Memory profiling in R</h1>
3836
(Intercept) log(Height) log(Girth)
3937
-6.632 1.117 1.983
4038

41-
> glm(log(Volume)~log(Height)+log(Girth),data=trees)
42-
memtrace[0xa499a88->0x9f5c7a0]: glm
43-
memtrace[0x9f5c7a0->0x9f5c408]: glm
39+
> glm(log(Volume)~log(Height)+log(Girth),data=trees)
40+
memtrace[0x8bfff28->0x8b6d820]: glm
41+
memtrace[0x8b6d820->0x89b4c10]: glm
4442

4543
Call: glm(formula = log(Volume) ~ log(Height) + log(Girth), data = trees)
4644

@@ -51,20 +49,17 @@ <h1 align="center">Memory profiling in R</h1>
5149
Degrees of Freedom: 30 Total (i.e. Null); 28 Residual
5250
Null Deviance: 8.309
5351
Residual Deviance: 0.1855 AIC: -62.71
54-
> tracemem(trees$Volume)
55-
[1] "<0x9b45bc8>"
56-
> lm(Volume~Height+Girth,data=trees)
57-
memtrace[0x9b45bc8->0x9db3658]: eval eval model.frame.default model.frame eval eval lm
58-
memtrace[0x9db3658->0x9db39a0]: makepredictcall model.frame.default model.frame eval eval lm
59-
memtrace[0x9db3658->0x992b4a8]: <Anonymous> [[.data.frame [[ na.omit.data.frame na.omit model.frame.default model.frame eval eval lm
52+
> tracemem(trees$Volume)
53+
[1] "<0x895e230>"
54+
> lm(Volume~Height+Girth,data=trees)
55+
memtrace[0x895e230->0x87a2898]: eval eval model.frame.default model.frame eval eval lm
6056

6157
Call:
6258
lm(formula = Volume ~ Height + Girth, data = trees)
6359

6460
Coefficients:
6561
(Intercept) Height Girth
6662
-57.9877 0.3393 4.7082
67-
6863
</pre>
6964
<code>tracemem</code> cannot be used on functions, since it uses the same trace bit that <code>trace</code> uses, 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.
7065

@@ -76,6 +71,6 @@ <h1 align="center">Memory profiling in R</h1>
7671
Valgrind can also help with memory profiling at the C level, using <code>--tool=massif</code>
7772

7873
<hr>
79-
Thomas Lumley. 2006-5-10
74+
Thomas Lumley. 2006-8-1
8075
<p>
8176

0 commit comments

Comments
 (0)