time
is a brilliant command if you want to figure out how much CPU time a given command takes.
I am looking for something similar that can measure the max RAM usage of the program and any children. Preferably it should distinguish between allocated memory that was used and unused. Maybe it could even give the median memory usage (so the memory usage you should expect when running for a long time).
So I would like to do:
rammeassure my_program my_args
and get output similar to:
Max memory allocated: 10233303 Bytes
Max memory used: 7233303 Bytes
Median memory allocation: 5233303 Bytes
I have looked at memusg
https://gist.github.com/526585/590293d6527c91e48fcb08edb8de9fd6c88a6d82 but I regard that as somewhat a hack.
wait3
fills a structure which is described ingetrusage(2)
: 'Not all fields are meaningful under Linux. [..]'. – maxschlepzig Aug 16 '11 at 19:49tstime
reports 10652 KiB. Again under Ubuntu 10.04. – maxschlepzig Aug 16 '11 at 19:58/usr/bin/time -v perl -e '$a="x"x100000000;$b=$a.$a;sleep 10;'
. top says it takes around 570 MB, but time says 2.3 GB. In practice that number is not usuable to me. – Ole Tange Aug 22 '11 at 11:56command time -v <program>
to get the right version oftime
. This was on Ubuntu 22.04 with bash. – Thorkil Værge Oct 18 '22 at 13:08