memusage(1) General Commands Manual memusage(1) memusage - memusage [option ...] program [programoption ...] memusage bash(1) program. libmemusage.so ( LD_PRELOAD ld.so(8)). libmemusage.so malloc(3) calloc(3) free(3) realloc(3) mmap(2) mremap(2) munmap(2). memusage memusagestat(1) ( -p ) PNG . " " memusage : heap total size malloc(3) (n*size) calloc(3) length mmap(2). realloc(3) mremap(2) ( ). heap peak size malloc(3) n*size calloc(3) size realloc(3) length mmap(2) new_size mremap(2). stack peak ( ). . . . realloc(3) mremap(2) "nomove" "dec" . realloc(3) "free" ( 0). "realloc/total memory" memusage realloc(3) . "total memory" ( "free") "free/total memory". "Histogram for block sizes" . -n --progname=name . -p --png=file PNG file. -d --data=file file. -u --unbuffered . -b --buffer=size size . --no-timer (SIGPROF) . -m --mmap mmap(2) mremap(2) munmap(2). -? --help . --usage . -V --version . : -t --time-based ( ) X. -T --total . --title=name name . -x size --x-size= size . -y size --y-size= size . memusage . . memusage.png: $ memusage --data=memusage.dat ./a.out; ... 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% ================ $ memusagestat memusage.dat memusage.png; #include #include #define CYCLES 20 int main(int argc, char *argv[]) { int i, j; size_t size; int *p; size = sizeof(*p) * 100; printf("malloc: %zu\n", size); p = malloc(size); for (i = 0; i < CYCLES; i++) { if (i < CYCLES / 2) j = i; else j--; size = sizeof(*p) * (j * 50 + 110); printf("realloc: %zu\n", size); p = realloc(p, size); size = sizeof(*p) * ((j + 1) * 150 + 110); printf("realloc: %zu\n", size); p = realloc(p, size); } free(p); exit(EXIT_SUCCESS); } memusagestat(1), mtrace(1), ld.so(8) 3 . . : . 6.18 8 2026 memusage(1)