linux – 如何测量应用程序或进程的实际内存使用情况?



Understanding memory usage on Linux的博客文章,ps不是用于此意图的准确工具。

Why ps is “wrong”

Depending on how you look at it, ps is not reporting the real memory usage of processes. What it is really doing is showing how much real memory each process would take up if it were the only process running. Of course, a typical Linux machine has several dozen processes running at any given time, which means that the VSZ and RSS numbers reported by ps are almost definitely wrong.



如果你真的想知道你的应用程序实际使用的内存量,你需要在分析器中运行它。例如,valgrind可以让您了解所使用的内存量,更重要的是,您的程序可能出现的内存泄漏。 valgrind的heap profiler工具称为“massif”:

Massif is a heap profiler. It performs detailed heap profiling by taking regular snapshots of a program’s heap. It produces a graph showing heap usage over time, including information about which parts of the program are responsible for the most memory allocations. The graph is supplemented by a text or HTML file that includes more information for determining where the most memory is being allocated. Massif runs programs about 20x slower than normal.

valgrind documentation中所解释的,您需要通过valgrind运行程序:

valgrind --tool=massif <executable> <arguments>



转载请明显位置注明出处:linux – 如何测量应用程序或进程的实际内存使用情况?