You can get the peak memory usage of a certain process, at:
grep VmPeak /proc/$PID/status
(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.
#!/bin/bash
#
# Parameters:
#
# config (required)
# autoconf (optional - used by munin-config)
#
COMPONENT_NAME="Apache"
COMPONENT_PID_FILE="/var/run/apache2.pid"
if [ "$1" = "autoconf" ]; then
if [ -r /proc/stat ]; then
echo yes
exit 0
else
echo "no (/proc/stat not readable)"
exit 1
fi
fi
if [ "$1" = "config" ]; then
echo "graph_title $COMPONENT_NAME memory usage"
echo 'graph_vlabel'
echo "graph_category Processes"
echo "graph_info This graph shows the amount of memory used by the $COMPONENT_NAME processes"
echo "${COMPONENT_NAME}_vmpeak.label $COMPONENT_NAME VmPeak"
echo "${COMPONENT_NAME}_vmsize.label $COMPONENT_NAME VmSize"
echo "${COMPONENT_NAME}_vmrss.label $COMPONENT_NAME VmRSS"
echo 'graph_args --base 1024'
exit 0
fi
check_memory ()
# $1 - PID location
# $2 - process_label
{
pid_location=$1
process_label=$2
read pid < $pid_location
procpath="/proc/$pid/status"
if [ ! -e $procpath ] || [ -z $pid ]
then
echo "${process_label}_vmpeak.value 0"
echo "${process_label}_vmsize.value 0"
echo "${process_label}_vmrss.value 0"
exit 0
fi
VmPeak=`grep VmPeak /proc/$pid/status|awk '{print $2}'`
VmSize=`grep VmSize /proc/$pid/status|awk '{print $2}'`
VmRSS=`grep VmRSS /proc/$pid/status|awk '{print $2}'`
echo "${process_label}_vmpeak.value $(( $VmPeak * 1024 ))"
echo "${process_label}_vmsize.value $(( $VmSize * 1024 ))"
echo "${process_label}_vmrss.value $(( $VmRSS * 1024 ))"
}
check_memory $COMPONENT_PID_FILE $COMPONENT_NAME
The VmPeak answer looks like a good one to me... You could either append vmpeak to a file every x seconds and then find the highest value. Or, every x seconds, run something like: VmPeak = curVmPeak if (curVmPeak > VmPeak)
.
Best Answer
I'm not sure how you dump all the memory to a file without doing this repeatedly (if anyone knows an automated way to get gdb to do this please let me know), but the following works for any one batch of memory assuming you know the pid:
This will be in the format (example):
Pick one batch of memory (so for example 00621000-00622000) then use gdb as root to attach to the process and dump that memory:
Then analyse /root/output with the strings command, less you want the PuTTY all over your screen.