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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With