I needed to figure out a firefox memory footprint and it is inconvenient given it is one parent and many child processes. So, here is the shell script (runs on Ubuntu and CentOS), which collects the data based on the parent’s pid:
#!/bin/bash
function memlog {
[ -d "/proc/${1}" ] || {
echo "The process ${1} does not exist" 1>&2
return 1
}
nap=5
while true
do
ps -o rss,vsz --pid ${1} --ppid ${1} --no-headers | {
rss=0
vsz=0
while read r v
do
(( rss = rss + r ))
(( vsz = vsz + v ))
done
printf "%(%Y-%m-%d %H:%M:%S %z)T,%d,%d,%d\n" -1 ${1} ${rss} ${vsz}
}
sleep ${nap}
done
}
memlog ${1}
One can run multiple of those adding output to the same log file for late processing. For example, having:
$ ps -fp 188273,215622
UID PID PPID C STIME TTY TIME CMD
vlad 188273 23532 1 15:25 ? 00:04:30 /usr/lib/firefox/firefox -no-remote -P Facebook
vlad 215622 23532 9 22:08 ? 00:00:40 /usr/lib/firefox/firefox -no-remote -P Temp
$ memlog 188273 >>tmp/ffx.log & memlog 215622 >>tmp/ffx.log &
[1] 216553
[2] 216554
$
You may see in the output file:
$ tail -f tmp/ffx.log
2009-01-29 22:16:05 -0700,188273,1439644,39776816
2009-01-29 22:16:05 -0700,215622,1408660,14286552
2009-01-29 22:16:10 -0700,188273,1439220,39776816
2009-01-29 22:16:10 -0700,215622,1408328,14286552
^C
$
The fields are: timestamp, parent process ID, resident memory, virtual memory. One of the issues is that this will report on the immediate children of a process, not on further grandchildren and such.
2009-01-29