Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see heap and stack usage of a function in c using valgrind?

I am working on a embedded system. We have limited stack and heap in our embedded system typically 64k (ram). I am trying to use polar-ssl library calls. Is there any tools which tells how much stack and heap memory is used by a C function?

Is there any option is in valgrind which prints the following:

  1. Stack and heap usage of a function.
  2. Call trace of functions which calls internally malloc with no of bytes.
like image 675
yuvaeasy Avatar asked Apr 30 '12 09:04

yuvaeasy


People also ask

How do you check valgrind logs?

If you give the -v option, Valgrind will print the list of used suppressions at the end of execution. For a leak suppression, this output gives the number of different loss records that match the suppression, and the number of bytes and blocks suppressed by the suppression.

Can valgrind detect stack corruption?

My other usual go-to for debugging memory issues, valgrind, also doesn't work very well for stack issues - it's much better at tracking heap allocations and writes than stack problems.

How do I get more information from valgrind?

Valgrind includes an option to check for memory leaks. With no option given, it will list a heap summary where it will say if there is any memory that has been allocated but not freed. If you use the option --leak-check=full it will give more information.


1 Answers

There is a valgrind tool massif that measures how much heap memory an application uses. Similarly memcheck can give you stack trace. More explanation here

http://wiki.eclipse.org/Linux_Tools_Project/Valgrind/User_Guide#Analyzing_Memcheck_Profile_Results

like image 135
anurag-jain Avatar answered Oct 02 '22 21:10

anurag-jain