Display resource usage

After a build job is done, display some statistics like average and maximum CPU, RAM, swap, network and disk usage and how long each one was the bottle-neck.
Currently my build stops because it produced no output for 10 minutes. I suspect it to require too much RAM, which causes it to swap and become extremely slow, but I don’t know how to check.
Also seeing things like “Used 17.6/18GB disk space” help to be proactive.