memusagestat.1: Various additions and improvements

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Michael Kerrisk 2014-09-01 14:30:34 +02:00
parent 16e05f30d6
commit a863cb3a4c
1 changed files with 75 additions and 56 deletions

View File

@ -20,96 +20,115 @@
.\" License along with this manual; if not, see
.\" <http://www.gnu.org/licenses/>.
.\" %%%LICENSE_END
.TH MEMUSAGESTAT 1 2013-04-10 "GNU glibc 2.18" "Memory diagnostic tools"
.TH MEMUSAGESTAT 1 2013-04-10 "GNU" "Linux programmer's manual"
.SH NAME
memusagestat \- generate graphic from memory profiling data
.SH SYNOPSIS
.BR memusagestat " [\fIoption\fR]... \fIdatafile\fR [\fIoutfile\fR]"
.SH DESCRIPTION
.B memusagestat
can create a PNG file with graphical representation of memory profiling
data.
Red line in the graph shows the heap usage (allocated memory),
green line shows the stack usage,
x-scale number of memory handling functions calls or time (\fB-t\fR option).
.I datafile
is a binary data file generated by
.BR memusage (1)
utility with
.B -d
option.
creates a PNG file containing a graphical representation of the
memory profiling data in the file
.IR datafile ;
that file is generated via the
.I -d
(or
.IR --data )
option of
.BR memusage (1).
The red line in the graph shows the heap usage (allocated memory)
and the green line shows the stack usage.
The x-scale is either the number of memory-handling function calls or
(if the
.I -t
option is specified)
time.
.SH OPTIONS
.TP
.BI \-o\ file \fR,\ \fB\-\-output= file
Name of the output file.
.TP
.BI \-s\ string \fR,\ \fB\-\-string= string
Title string used in the output graphic.
Use
.I string
as the title inside the output graph.
.TP
.BI \-t\fR,\ \fB\-\-time
Generate output linear to time
(default is linear to number of function calls).
Use time (rather than number of function calls) as the scale for the X axis.
.TP
.BI \-T\fR,\ \fB\-\-total
Also draw graph for total memory consumption.
Also draw a graph of total memory consumption.
.TP
.BI \-x\ size \fR,\ \fB\-\-x-size= size
Make graphic size pixels wide.
Make the output graph
.I size
pixels wide.
.TP
.BI \-y\ size \fR,\ \fB\-\-y\-size= size
Make graphic size pixels high.
Make the output graph
.I size
pixels high.
.TP
.BI \-?\fR,\ \fB\-\-help
Print help and exit.
Print a help message and exit.
.TP
.BI \fB\-\-usage
Print a short usage message and exit.
.TP
.BI \-V\fR,\ \fB\-\-version
Print version information and exit.
.SH EXAMPLES
Here is a simple program \fImemusagestatexample.c\fR simulating increase
and decrease of memory usage:
.SH EXAMPLE
Below is a simple program that reallocates a block of
memory in cycles that rise to a peak before then cyclically
reallocating the memory in smaller blocks that return to zero.
After compiling the program and running the following commands,
a graph of the memory usage of the program can be found in the file
.IR memusage.png :
.RS 4
.in +4n
.nf
$ \fBmemusage --data=memusage.dat ./a.out\fP
$ \fBmemusagestat memusage.dat memusage.png\fP
.fi
.in
.SS Program source
.nf
#include <stdio.h>
.RS 0
#include <stdlib.h>
.RE
.RS 0
#define CYCLES 20
.RE
int main(int argc, char ** argv) {
int i, j;
int *p = NULL;
printf("malloc: %d\\n", sizeof(int)*100);
p = malloc(sizeof(int)*100);
int
main(int argc, char *argv[])
{
int i, j;
int *p;
for (i = 0; i < CYCLES; i++) {
if (i < CYCLES/2) j = i; else j--;
printf("realloc: %d\\n", sizeof(int)*((j)*50 + 110));
p = realloc(p, sizeof(int)*(j*50 + 100));
printf("realloc: %d\\n", sizeof(int)*((j+1)*150 + 110));
p = realloc(p, sizeof(int)*((j+1)*150 + 110));
}
free(p);
return 0;
.RS 0
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
j--;
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);
}
.RE
.RE
After compiling and running the following, you can see progress of
memory usage (memusagestatexample.png):
memusage --data=memusagestatexample.dat ./memusagestatexample
.RS 0
memusagestat memusagestatexample.dat memusagestatexample.png
.RE
.fi
.SH BUGS
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
To report bugs, see
.UR http://www.gnu.org/software/libc/bugs.html
.UE
.SH SEE ALSO
.BR memusage (1)
.BR memusage (1),
.BR mtrace (1)