Tools like top and ps can give me the amount of memory currently allocated to a process, but I am interested in measuring the maximum amount of memory allocated to a process either since its creation or in a given time interval. Any suggestions on how to find out?
You can get the peak memory usage of a certain process, at:
(Change $PID to the actual process id you're looking for).
VmPeak is the maximum amount of memory the process has used since it was started.
In order to track the memory usage of a process over time, you can use a tool called munin to track, and show you a nice graph of the memory usage over time.
Munin comes with many default plugins to track system resources, however it doesn't come with a plugin to track Peak memory usage - fortunetly, its extremely easy to write a plugin for it.
Here's an example of a munin plugin to track VmPeak,VmRSS and VmSize memory usage , for the apache process. You can change this to suit your needs (just point to the right PID file and change the component name as needed).
The graph it outputs looks like this (VmPeak and VmSize are the same in this example, so you only see one of them):
Note: this only monitors the main apache process, and doesn't show the memory usage of it's child processes.
There are tools you can use when starting a process which give you a summary of the memory usage once the process finishes:
GNU time also gives the peak memory usage when executed with the -v option. Note that bash also has a built-in command called time, so you may need to specify the full path to GNU time when invoking it, e.g., /usr/bin/time -v command. Moreover, beware that older versions of GNU time have a bug where the results are incorrectly multiplied by 4, e.g., check the following link: https://bugzilla.redhat.com/show_bug.cgi?id=702826