The R Project SVN R

Rev

Rev 38426 | Rev 38705 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 38426 Rev 38550
Line 132... Line 132...
132
    errorcall(call,"R not compiled with memory profiling");
132
    errorcall(call,"R not compiled with memory profiling");
133
    return R_NilValue;
133
    return R_NilValue;
134
#endif
134
#endif
135
}
135
}
136
 
136
 
-
 
137
 
137
SEXP attribute_hidden do_memuntrace(SEXP call, SEXP op, SEXP args, SEXP rho)
138
SEXP attribute_hidden do_memuntrace(SEXP call, SEXP op, SEXP args, SEXP rho)
138
{
139
{
139
#ifdef R_MEMORY_PROFILING
140
#ifdef R_MEMORY_PROFILING
140
    SEXP object;
141
    SEXP object;
141
 
142
 
Line 159... Line 160...
159
#ifndef R_MEMORY_PROFILING
160
#ifndef R_MEMORY_PROFILING
160
void memtrace_report(SEXP old, SEXP new){
161
void memtrace_report(SEXP old, SEXP new){
161
     return;
162
     return;
162
}
163
}
163
#else
164
#else
164
void memtrace_report(SEXP old, SEXP new){
165
static void memtrace_stack_dump(void){
165
    RCNTXT *cptr;
166
    RCNTXT *cptr;
166
 
167
 
167
    if (!R_current_trace_state()) return;
-
 
168
    Rprintf("memtrace[%p->%p]: ",old,new);
-
 
169
    for (cptr = R_GlobalContext; cptr; cptr = cptr->nextcontext) {
168
    for (cptr = R_GlobalContext; cptr; cptr = cptr->nextcontext) {
170
	if ((cptr->callflag & (CTXT_FUNCTION | CTXT_BUILTIN))
169
	if ((cptr->callflag & (CTXT_FUNCTION | CTXT_BUILTIN))
171
	    && TYPEOF(cptr->call) == LANGSXP) {
170
	    && TYPEOF(cptr->call) == LANGSXP) {
172
	    SEXP fun = CAR(cptr->call);
171
	    SEXP fun = CAR(cptr->call);
173
	    Rprintf("%s ",
172
	    Rprintf("%s ",
Line 175... Line 174...
175
		    "<Anonymous>");
174
		    "<Anonymous>");
176
	}
175
	}
177
    }
176
    }
178
    Rprintf("\n");
177
    Rprintf("\n");
179
 
178
 
-
 
179
 
-
 
180
}
-
 
181
void memtrace_report(SEXP old, SEXP new){
-
 
182
    if (!R_current_trace_state()) return;
-
 
183
    Rprintf("memtrace[%p->%p]: ",old,new);
-
 
184
    memtrace_stack_dump();
180
}
185
}
181
 
186
 
182
#endif /* R_MEMORY_PROFILING */
187
#endif /* R_MEMORY_PROFILING */
-
 
188
 
-
 
189
SEXP attribute_hidden do_memretrace(SEXP call, SEXP op, SEXP args, SEXP rho)
-
 
190
{
-
 
191
#ifdef R_MEMORY_PROFILING
-
 
192
    SEXP object, origin, ans;
-
 
193
    char buffer[20];
-
 
194
 
-
 
195
    checkArity(op, args);
-
 
196
 
-
 
197
    object = CAR(args);
-
 
198
    if (TYPEOF(object) == CLOSXP || 
-
 
199
	TYPEOF(object) == BUILTINSXP ||
-
 
200
	TYPEOF(object) == SPECIALSXP)
-
 
201
	    errorcall(call, "argument must not be a function");
-
 
202
 
-
 
203
    origin = CADR(args);
-
 
204
 
-
 
205
    if (TRACE(object)){
-
 
206
	    sprintf(buffer, "<%p>", object);
-
 
207
	    ans= mkString(buffer);
-
 
208
    } else ans=R_NilValue;
-
 
209
 
-
 
210
    if (origin!=R_NilValue){
-
 
211
       SET_TRACE(object, 1);
-
 
212
       if (R_current_trace_state()) {
-
 
213
	       Rprintf("memtrace[%s->%p]: ",CHAR(STRING_ELT(origin, 0)), object);
-
 
214
	       memtrace_stack_dump();
-
 
215
       }
-
 
216
    }
-
 
217
    return ans;
-
 
218
#else
-
 
219
    return R_NilValue;
-
 
220
#endif
-
 
221
}