diff options
Diffstat (limited to 'man1/memusage.1')
| -rw-r--r-- | man1/memusage.1 | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/man1/memusage.1 b/man1/memusage.1 index 819c3d1aff..b615204c46 100644 --- a/man1/memusage.1 +++ b/man1/memusage.1 @@ -1,4 +1,5 @@ .\" Copyright (c) 2013, Peter Schiffer <pschiffe@redhat.com> +.\" and Copyright (C) 2014, Michael Kerrisk <mtk.manpages@gmail.com> .\" .\" %%%LICENSE_START(GPLv2+_DOC_FULL) .\" This is free documentation; you can redistribute it and/or @@ -198,8 +199,71 @@ pixels high. .SH EXIT STATUS Exit status is equal to the exit status of profiled program. .SH EXAMPLE -See -.BR memusagestat (1). +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 : + +.in +4n +.nf +$ \fBmemusage --data=memusage.dat ./a.out\fP +\&... +Memory usage summary: heap total: 45200, heap peak: 6440, stack peak: 224 + total calls total memory failed calls + malloc| 1 400 0 +realloc| 40 44800 0 (nomove:40, dec:19, free:0) + calloc| 0 0 0 + free| 1 440 +Histogram 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% ================ +$ \fBmemusagestat memusage.dat memusage.png\fP +.fi +.in +.SS Program source +.nf +#include <stdio.h> +#include <stdlib.h> + +#define CYCLES 20 + +int +main(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 + 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); +} +.fi .SH BUGS To report bugs, see .UR http://www.gnu.org/software/libc/bugs.html |
