Valgrind 3.3.0 and the new massif
I previously wrote a column on using valgrind, and I briefly touched on the massif tool. With the release of Valgrind 3.3.0, the massif tool got quite an overhaul. The output is no longer postscript by default, but instead is a massif.out.<pid>
file that can be post-processed by other tools. Currently the only tool to do this with is ms_print
.
Massif is invoked as before. The example command line below is for using it with pacman to test heap usage during a large sync operation. I wanted to do a before and after with our dynamic memory allocation changes and the removal of many unnecessary pkg_dup calls in the code. This was the root of FS#8155.
sudo valgrind --tool=massif --depth=4 --max-snapshots=200 ./src/pacman/.libs/lt-pacman --root /tmp/installroot/ -Sy base --noconfirm
I ran this command with two different cuts of code- the v3.1.1 tag of pacman, and the current master branch (which happened to be commit 88cbee). The results were quite interesting.
Because massif does not output a human friendly file by default, you have to post-process it with ms_print
. The following basic idea should get you started:
ms_print --x=132 --y=60 massif.out.2786 | less
With this all complete, I was able to produce the following two output files which show a huge improvement in the current pacman release and our working branch with the malloc and dup changes. You can see the old code uses much more memory at its maximum point than the new code- 13.9MB vs 5.3MB! In addition, the memory usage of the old code continuously grows because of the pkg_dup calls, while then new code stays at constant memory usage after all targets are loaded. This should make pacman fail early (if at all) when it comes to memory issues, rather than completing half of an install and dying.
See Also
- Using valgrind for C programming - November 18, 2007
- Road to pacman 3.2.0 - February 28, 2008
- i18n console output in C - February 15, 2012
- Unstated coding style - December 21, 2011
- C, unsigned integers, and the infinite for loop - July 19, 2011