memusage(1) General Commands Manual memusage(1) memusage - memusage [option ...] program [programoption ...] memusage is a bash(1) script which profiles memory usage of the program, program. It preloads the libmemusage.so library into the caller's environment (via the LD_PRELOAD environment variable; see ld.so(8)). The libmemusage.so library traces memory allocation by intercepting calls to malloc(3), calloc(3), free(3), and realloc(3); optionally, calls to mmap(2), mremap(2), and munmap(2) can also be intercepted. memusage , memusagestat(1) ( - ) , PNG, . memusage " " : heap total Sum of size arguments of all malloc(3) calls, products of arguments (n*size) of all calloc(3) calls, and sum of length arguments of all mmap(2) calls. In the case of realloc(3) and mremap(2), if the new size of an allocation is larger than the previous size, the sum of all such differences (new size minus old size) is added. heap peak Maximum of all size arguments of malloc(3), all products of n*size of calloc(3), all size arguments of realloc(3), length arguments of mmap(2), and new_size arguments of 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 , , , Kirill Rekhov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () <>. Linux man-pages 6.12 25 2024 . memusage(1)