Commit f4069cc4 authored by Radford Neal's avatar Radford Neal

added bytes argument to Rprofmemt

parent 0ae328eb
......@@ -199,6 +199,9 @@
\item The \code{memory.profile} function now has an argument that can
restrict the counts for vector objects to only those of some minimum
length.
\item The \code{Rprofmemt} function now has a \code{bytes} argument, which
can be set to \code{FALSE} to suppress output of the number of bytes
allocated (useful for producing platform-independent output).
\item When the \code{unlist} and \code{c} functions create names for their
result, the situations in which a sequence number is appended to a
name are now the same for atomic vectors and lists. For example,
......
......@@ -11,3 +11,4 @@ Added chkDots from R-3.3.0; use in seq.R, lm.R, and density.R.
Added startsWith and endsWith from R-3.3.0.
Added bytes arg to Rprofmemt.
......@@ -25,17 +25,19 @@ Rprof <- function(filename = "Rprof.out", append = FALSE, interval = 0.02,
# Enhanced Rprofmem for pqR. Rprofmemt has different defaults.
Rprofmem <- function(filename = "Rprofmem.out", append = FALSE, threshold = 0,
nelem = 0, stack=TRUE, terminal = FALSE, pages = TRUE, details = FALSE)
nelem = 0, stack=TRUE, terminal = FALSE, pages = TRUE,
details = FALSE, bytes = TRUE)
{
if(is.null(filename)) filename <- ""
invisible(.Internal(Rprofmem(filename, append, as.double(threshold),
as.double(nelem), stack, terminal, pages, details)))
as.double(nelem), stack, terminal, pages, details, bytes)))
}
Rprofmemt <- function(filename = "", append = FALSE, threshold = 0,
nelem = 0, stack=TRUE, terminal = TRUE, pages = FALSE, details = TRUE)
nelem = 0, stack=TRUE, terminal = TRUE, pages = FALSE,
details = TRUE, bytes = TRUE)
{
if(is.null(filename)) { filename <- ""; terminal <- FALSE }
invisible(.Internal(Rprofmem(filename, append, as.double(threshold),
as.double(nelem), stack, terminal, pages, details)))
as.double(nelem), stack, terminal, pages, details, bytes)))
}
......@@ -14,11 +14,13 @@
\usage{
Rprofmem(filename = "Rprofmem.out", append = FALSE,
threshold = 0, nelem = 0, stack = TRUE,
terminal = FALSE, pages = TRUE, details = FALSE)
terminal = FALSE, pages = TRUE,
details = FALSE, bytes = TRUE)
Rprofmemt(filename = "", append = FALSE,
threshold = 0, nelem = 0, stack = TRUE,
terminal = TRUE, pages = FALSE, details = TRUE)
threshold = 0, nelem = 0, stack = TRUE,
terminal = TRUE, pages = FALSE,
details = TRUE, bytes = TRUE)
}
\arguments{
\item{filename}{The file to which reports of memory allocations are written,
......@@ -33,8 +35,9 @@ Rprofmemt(filename = "", append = FALSE,
\item{terminal}{logical: should reports be printed on the terminal (as
well as possibly written to \code{filename})?}
\item{pages}{logical: ignored, but retained for compatibility}
\item{details}{logical: should details of allocation be reported,
rather than only the total number of bytes?}
\item{details}{logical: should details (type, length) of the allocation
be reported?}
\item{bytes}{logical: should the number of bytes allocated be reported?}
}
\details{
The profiler tracks memory allocations, some of which will be to previously
......@@ -68,6 +71,10 @@ Rprofmemt(filename = "", append = FALSE,
\code{details=TRUE}, the type and length of the vector allocated will be
displayed in parentheses (before the call stack).
Output of the number of bytes allocated can be suppressed using
\code{bytes = FALSE}. This is mainly useful for producing output that
is platform-independent, as is useful for testing.
When \code{terminal=TRUE} or \code{details=TRUE}, a newline is always
written after each allocation report. For backward compatibility, this
is otherwise not the case when the call stack is empty.
......
......@@ -208,6 +208,7 @@ static int R_IsMemReporting;
static int R_MemReportingToTerminal;
static int R_MemStackReporting;
static int R_MemDetailsReporting;
static int R_MemBytesReporting;
static FILE *R_MemReportingOutfile;
static R_size_t R_MemReportingThreshold;
static R_len_t R_MemReportingNElem;
......@@ -2682,22 +2683,21 @@ static void R_ReportAllocation (SEXP s)
if (size > R_MemReportingThreshold && length >= R_MemReportingNElem) {
if (R_MemReportingOutfile != NULL) {
if (R_MemDetailsReporting)
fprintf (R_MemReportingOutfile, "%llu (%s %lu)",
(unsigned long long) size, type2char(type),
(unsigned long)length);
else
if (R_MemBytesReporting)
fprintf (R_MemReportingOutfile, "%llu ",
(unsigned long long) size);
(unsigned long long) size);
if (R_MemDetailsReporting)
fprintf (R_MemReportingOutfile, "(%s %lu)",
type2char(type), (unsigned long)length);
}
if (R_MemReportingToTerminal) {
REprintf ("RPROFMEM: ");
if (R_MemBytesReporting)
REprintf ("%llu ",
(unsigned long long) size);
if (R_MemDetailsReporting)
REprintf("RPROFMEM: %llu (%s %lu)",
(unsigned long long) size, type2char(type),
(unsigned long)length);
else
REprintf ("RPROFMEM: %llu ",
(unsigned long long) size);
REprintf("(%s %lu)",
type2char(type), (unsigned long)length);
}
R_OutputStackTrace();
}
......@@ -2769,6 +2769,9 @@ static SEXP do_Rprofmem(SEXP call, SEXP op, SEXP args, SEXP rho)
ap = CDR(ap);
R_MemDetailsReporting = asLogical(CAR(ap));
ap = CDR(ap);
R_MemBytesReporting = asLogical(CAR(ap));
if (R_MemReportingToTerminal || strlen(CHAR(filename)) > 0)
R_InitMemReporting(filename, append_mode);
else
......@@ -3600,7 +3603,7 @@ attribute_hidden FUNTAB R_FunTab_memory[] =
{"mem.limits", do_memlimits, 0, 11, 2, {PP_FUNCALL, PREC_FN, 0}},
{"memory.profile",do_memoryprofile, 0, 11, 1, {PP_FUNCALL, PREC_FN, 0}},
{"pnamedcnt", do_pnamedcnt, 0, 1, -1, {PP_FUNCALL, PREC_FN, 0}},
{"Rprofmem", do_Rprofmem, 0, 11, 8, {PP_FUNCALL, PREC_FN, 0}},
{"Rprofmem", do_Rprofmem, 0, 11, 9, {PP_FUNCALL, PREC_FN, 0}},
{"object.size", do_objectsize, 0, 11, 1, {PP_FUNCALL, PREC_FN, 0}},
{"testvalgrind",do_testvalgrind,0, 111, 1, {PP_FUNCALL, PREC_FN, 0}},
......
......@@ -6,7 +6,7 @@ options(keep.source=FALSE) # avoid allocations for source references
print(1) # get some stuff allocated before Rprofmemt activatived.
vsize <- 100 # must be multiple of 4
Rprofmemt(nelem=vsize)
Rprofmemt(nelem=vsize,bytes=FALSE)
# One-level assignments.
......@@ -138,7 +138,7 @@ print(a$q$x)
Rprofmemt(NULL)
setClass ("george", representation(a="numeric",b="logical"))
Rprofmemt(nelem=vsize)
Rprofmemt(nelem=vsize,bytes=FALSE)
ia <- rep(1.2,vsize)
ib <- rep(c(TRUE,FALSE),length=vsize)
......@@ -152,7 +152,7 @@ x@b[3] <- NA # should duplicate at most one, but currently dups four things
Rprofmemt(NULL)
print(x)
Rprofmemt(nelem=vsize)
Rprofmemt(nelem=vsize,bytes=FALSE)
# Things that should use VARIANT_UNCLASS, VARIANT_ANY_ATTR, or
......@@ -171,7 +171,7 @@ attr(B,"fred") <- rep("a",vsize)
o <- (1:vsize) + 0.5
class(o) <- "abc"
Rprofmemt(nelem=vsize)
Rprofmemt(nelem=vsize,bytes=FALSE)
for (i in a) print (i)
for (i in exp(a)) print (i)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment