Linux "memusage" Command Line Options and Examples
profile memory usage of a program

memusage is a bash script which profiles memory usage of the program, program. It preloads the libmemusage.so library into the call‐ er's environment (via the LD_PRELOAD environment variable; see ld.


Usage:

memusage [option]... program [programoption]...






Command Line Options:

-n
Name of the program file to profile.
memusage -n ...
-p
Generate PNG graphic and store it in file.
memusage -p ...
-d
Generate binary data file and store it in file.
memusage -d ...
-u
Do not buffer output.
memusage -u ...
-b
Collect size entries before writing them out.
memusage -b ...
--no-timer
Disable timer-based (SIGPROF) sampling of stack pointer value.
memusage --no-timer ...
-m
Also trace mmap(2), mremap(2), and munmap(2).
memusage -m ...
-?
Print help and exit.
memusage -? ...
--usage
Print a short usage message and exit.
memusage --usage ...
-V
Print version information and exit.The following options apply only when generating graphical output:
memusage -V ...
-t
Use time (rather than number of function calls) as the scale for the X axis.
memusage -t ...
-T
Also draw a graph of total memory use.
memusage -T ...
--title
Use name as the title of the graph.
memusage --title ...
-x
Make the graph size pixels wide.
memusage -x ...
-y
Make the graph size pixels high.EXIT STATUSExit status is equal to the exit status of profiled program.BUGSTo report bugs, see ⟨http://www.gnu.org/software/libc/bugs.html⟩EXAMPLEBelow is a simple program that reallocates a block of memory in cycles that rise to a peak before then cyclically reallocating thememory in smaller blocks that return to zero. After compiling the program and running the following commands, a graph of the memoryusage of the program can be found in the file memusage.png:$ memusage --data=memusage.dat ./a.out...Memory usage summary: heap total: 45200, heap peak: 6440, stack peak: 224total calls total memory failed callsmalloc| 1 400 0realloc| 40 44800 0 (nomove:40, dec:19, free:0)calloc| 0 0 0free| 1 440Histogram for block sizes:192-207 1 2% ================...2192-2207 1 2% ================2240-2255 2 4% =================================2832-2847 2 4% =================================3440-3455 2 4% =================================4032-4047 2 4% =================================4640-4655 2 4% =================================5232-5247 2 4% =================================5840-5855 2 4% =================================6432-6447 1 2% ================$ memusagestat memusage.dat memusage.pngProgram source#include <stdio.h>#include <stdlib.h>#define CYCLES 20intmain(int argc, char *argv[]){int i, j;int *p;printf("malloc: %zd\n", sizeof(int) * 100);p = malloc(sizeof(int) * 100);for (i = 0; i < CYCLES; i++) {if (i < CYCLES / 2)j = i;else
memusage -y ...
--;
printf("realloc: %zd\n", sizeof(int) * (j * 50 + 110));p = realloc(p, sizeof(int) * (j * 50 + 100));printf("realloc: %zd\n", sizeof(int) * ((j+1) * 150 + 110));p = realloc(p, sizeof(int) * ((j + 1) * 150 + 110));}free(p);exit(EXIT_SUCCESS);}
memusage --; ...