Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to profile memory usage of a C program

I need to figure out which part of a linux program that I am running, is taking how much (either percentage, or absolute) memory. I need to create a profile of multiple such programs, so that I can identify some of the bigger consumers of memory in my code, and see if I can optimize them to use less. I need it on MIPS platform, and unfortunately, Valgrind doesn't work on MIPS.

Any help/pointers would be greatly appreciated.

like image 609
Harty Avatar asked Dec 15 '09 09:12

Harty


2 Answers

Beside Valgrind, there exists a lot of other memory debugger/profiler. All the following seems to support MIPS (but I've not tried them on that architecture) :

jemalloc, CCMALLOC, mpatrol, NJAMD, Dmalloc, and even Google's own google-perftools.

like image 91
Laurent Parenteau Avatar answered Sep 18 '22 04:09

Laurent Parenteau


You could wrap all your calls to free and malloc with your own functions in which you also supply for instance in which file and at what line number each allocation is done. From this information it's easy to see what memory is being used where.

like image 30
Andreas Brinck Avatar answered Sep 22 '22 04:09

Andreas Brinck