Peak RAM usage of process and its children

Measuring the peak RAM usage of a process and all its children can be done using various tools and techniques. OS-dependent tools may be the most accurate, but they can be complex to use. A simpler approach is to periodically sample the RAM usage of the process and its children, like this scripts for Linux and macOS using ps.

It is also possible though less accurate on macOS or Linux to use /usr/bin/time, but this only measures the peak RAM usage of the largest child process, not the total of all children, so this is unsuitable for multiprocess applications like “mpiexec”.

For Linux, a more accurate method is the Cgroup v2, such as implemented by cgmemtime. For macOS, the Instruments tool can be used to measure the RAM usage of a process and its children, but it requires a ‘codesign’d application and is more complex to set up.

xcrun xctrace record --template "Game Memory" --launch -- /path/to/application --output bench_game.trace --time-limit 30s

open bench_game.trace