Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use valgrind for memory profile

Tags:

linux

valgrind

Can you please tell me how can I use valgrind for memory profile? The article I found from google talks about how to use valgrind for memory leak. I am interested in how to use that for memory profiling (i.e. how much memory is used by what classes)?

Thank you.

like image 751
michael Avatar asked Mar 18 '10 21:03

michael


People also ask

How do you use Valgrind profile?

To profile, you run your program under Valgrind and explicitly request the callgrind tool (if unspecified, the tool defaults to memcheck). Valgrind has written the information about the above 7 million collected events to an output file named callgrind.

How do you run a Valgrind memory leak?

To run Valgrind, pass the executable as an argument (along with any parameters to the program). The flags are, in short: --leak-check=full : "each individual leak will be shown in detail" --show-leak-kinds=all : Show all of "definite, indirect, possible, reachable" leak kinds in the "full" report.

Can Valgrind find memory corruption?

Valgrind Memcheck is a tool that detects memory leaks and memory errors. Some of the most difficult C bugs come from mismanagement of memory: allocating the wrong size, using an uninitialized pointer, accessing memory after it was freed, overrunning a buffer, and so on.


1 Answers

You can use valgrind's Massif tool to get a heap profile. This code is still labelled "experimental", and it does not ship with all versions of valgrind. You may have to download and build from source.

Also note that the heap profile is organized by allocation site, which is a finer granularity than classes. If you need information organized by class, you will have to read the developer documentation and get the machine-readable format, then figure out which allocation sites go with which classes - perhaps with support from your compiler.

Even without support for classes, however, the Massif profile may be useful.

like image 78
Norman Ramsey Avatar answered Nov 03 '22 00:11

Norman Ramsey