Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory profiler for C [closed]

I need a memory profiler to know the memory usage for each function. I know valgrind (Massif) but it doesn't give me information about specific functions (at least, I don't know how to do it with massif)

Do you know any tool for this purpose in Linux?

Thanks!

like image 634
lezo Avatar asked Jan 04 '11 11:01

lezo


People also ask

What is memory profiling in C?

Memory Profiling uses Source Code Insertion Technology for C and C++. Because of the different technologies involved, Memory Profiling for Java is covered in a separate section. Memory Profiling for C and C++ supports the following languages: C: ANSI 89, ANSI 99, or K&R C. C++: ISO/IEC 14882:1998.

What is a memory profiler?

Memory profiling enables you to understand the memory allocation and garbage collection behavior of your applications over time. It helps you identify method calls in the context within which most memory was allocated and combine this information with the number of allocated objects.

How do memory profilers work?

The most common type of profiler is the sampling profiler. They work by interrupting the application under test periodically in proportion to the consumption of the resource we're interested in. While the program is interrupted the profiler grabs a snapshot of its current state, which includes where in the code it is.


1 Answers

Massif does show you which functions were responsible for the memory usage, as long as you've compiled your program with debugging info (-g). It will even show you the line number.

This information is given as a call tree in each detailed snapshot under the graph in the ms_print output. The frequency of detailed snapshots can be controlled with the --detailed-freq option to massif. See Section 9.2.6 of the Massif manual for details on reading the detailed snapshot information.

like image 155
caf Avatar answered Oct 07 '22 13:10

caf