memusage(1) General Commands Manual memusage(1) memusage - memusage [] [_] memusage bash, . 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) ( - ) , PNG, . memusage " " : heap total size malloc (3), (nmemb*size) calloc(3) length mmap (2) . realloc (3) mremap (2), , , ( ). heap peak size malloc(3), nmemb*size calloc(3), size realloc(3), length mmap(2) new_size mremap(2). stack peak ( ). . . , . realloc(3) mremap(2) <>, , , <>, , . realloc(3) <> , (. ., 0). <>, memusage, , realloc(3) , . , <> ( <>) , <>. << >> . -n , --progname= . -p file, --png=file PNG file. -d , --data= . -u, --unbuffered . -b size, --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= . -x size, --x-size=size size . -y size, --y-size=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) aereiae , Alexey , Azamat Hackimov , Dmitriy S. Seregin , Dmitry Bolkhovskikh , ITriskTI , Max Is , Yuri Kozlov , , ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . memusage(1)