Is there a tool that will run a command-line and report how much RAM was used total?
I'm imagining something analogous to /usr/bin/time
Is there a tool that will run a command-line and report how much RAM was used total?
I'm imagining something analogous to /usr/bin/time
On macOS, you can use DTrace instead. The "Instruments" app is a nice GUI for that, it comes with XCode afaik.
Valgrind one-liner:
valgrind --tool=massif --pages-as-heap=yes --massif-out-file=massif.out ./test.sh; grep mem_heap_B massif.out | sed -e 's/mem_heap_B=\(.*\)/\1/' | sort -g | tail -n 1
Note use of --pages-as-heap to measure all memory in a process. More info here: http://valgrind.org/docs/manual/ms-manual.html
If the process runs for at least a couple seconds, then you can use the following bash script, which will run the given command line then print to stderr the peak RSS (substitute for
rss
any other attribute you're interested in). It's somewhat lightweight, and it works for me with theps
included in Ubuntu 9.04 (which I can't say fortime
).Heaptrack is KDE tool that has a GUI and text interface. I find it more suitable than valgrind to understand the memory usage of a process because it provides more details and flamegraphs. It's also faster because it does less checking that valgrind. And it gives you the peak memory usage.
Anyway, tracking rss and vss is misleading because pages could be shared, that's why that
memusg
. What you should really do is track the sum ofPss
in/proc/[pid]/smaps
or usepmap
. GNOME system-monitor used to do so but it was too expensive.Re-inventing the wheel, with hand made bash script. Quick and clean.
My use case: I wanted to monitor a linux machine which has less RAM and wanted to take a snapshot of per container usage when it runs under heavy usage.
Sample output: