I'm currently developing a C++ app on an Ubuntu 16.04 virtual machine. I need to measure the total memory usage of the app (stack and heap) in order to find out its maximum value range. Since I'm quite new at memory profiling, I ended up using valgrind as follows:commands:
valgrind --tool=massif --stacks=yes ./c++_app
ms_print massif.out.<PID>
In the decoded file I got a spike of 12.5 MB on the relevant graph. On the other side the gnome-system-monitor showed 25 MB as the maximum memory value.
Which of the two results should I trust? Should one cross-check the memory usage with other software as well?
Both results are probably correct. Massif profiles heap and possibly stack. The system monitor on the other hand provides info about the total memory usage, including size of the running image (which also includes static data memory).
For your question, you should rely on the massif results.