Massif: a heap profiler
responsible for more than 1% of useful memory bytes, and ms_print likewise only prints the details for code locations
responsible for more than 1%. The entries that do not meet this threshold are aggregated. This avoids filling up the
output with large numbers of unimportant entries.
The thresholds can be changed with the
--threshold
option
that both Massif and ms_print support.
9.2.7. Forking Programs
If your program forks, the child will inherit all the profiling data that has been gathered for the parent.
If the output file format string (controlled by
--massif-out-file
) does not contain
%p
, then the outputs from
the parent and child will be intermingled in a single output file, which will almost certainly make it unreadable by
ms_print.
9.2.8. Measuring All Memory in a Process
It is worth emphasising that by default Massif measures only heap memory, i.e. memory allocated with
malloc
,
calloc
,
realloc
,
memalign
,
new
,
new[]
, and a few other, similar functions. (And it can optionally measure
stack memory, of course.) This means it does
not
directly measure memory allocated with lower-level system calls
such as
mmap
,
mremap
, and
brk
.
Heap allocation functions such as
malloc
are built on top of these system calls.
For example, when needed, an
allocator will typically call
mmap
to allocate a large chunk of memory, and then hand over pieces of that memory
chunk to the client program in response to calls to
malloc
et al. Massif directly measures only these higher-level
malloc
et al calls, not the lower-level system calls.
Furthermore, a client program may use these lower-level system calls directly to allocate memory. By default, Massif
does not measure these.
Nor does it measure the size of code, data and BSS segments.
Therefore, the numbers
reported by Massif may be significantly smaller than those reported by tools such as
top
that measure a program’s
total size in memory.
However, if you wish to measure
all
the memory used by your program, you can use the
--pages-as-heap=yes
.
When this option is enabled, Massif’s normal heap block profiling is replaced by lower-level page profiling. Every
page allocated via
mmap
and similar system calls is treated as a distinct block.
This means that code, data and
BSS segments are all measured, as they are just memory pages.
Even the stack is measured, since it is ultimately
allocated (and extended when necessary) via
mmap
; for this reason
--stacks=yes
is not allowed in conjunction
with
--pages-as-heap=yes
.
After
--pages-as-heap=yes
is used, ms_print’s output is mostly unchanged. One difference is that the start of
each detailed snapshot says:
(page allocation syscalls) mmap/mremap/brk, --alloc-fns, etc.
instead of the usual
:
(heap allocation functions) malloc/new/new[], --alloc-fns, etc.
The stack traces in the output may be more difficult to read, and interpreting them may require some detailed
understanding of the lower levels of a program like the memory allocators.
But for some programs having the
full information about memory usage can be very useful.
145