On Wed, 22 Jul 2009, Scotty Logan wrote:
> On Jul 22, 2009, at 4:39 PM, Eben King wrote:
>> Is there a way to get more precise information about how much RAM/swap a
>> process uses? For instance, this line from top:
>>
>> PID USER NI VIRT RES SHR WCHAN S %CPU %MEM TIME COMMAND
>> 19252 eben 0 1097m 529m 19m - S 15 13.4 409:18 firefox
>>
>> that shows the important data (VIRTual, RESident, and SHaRed) has 2-4 digit
>> resolution. 4's good, 2's not. Straight page count would be best, of
>> course. Never mind the width; this isn't for (direct) human consumption
>> anyway.
>
>
> look in /proc/PID/stat and /proc/PID/statm
>
> man proc for details.
Thanks. Here it is. This can be modified to watch any suspect process.
One of these days I'll modify both ends to store the page count instead of
the byte count, since that involves fewer computational steps.
ff-log.sh (invoke as "ff-log.sh >> /tmp/firefox-log.txt &"):
#! /bin/sh
kilo=1024
page=$((kilo*4))
mega=$((kilo*1024))
giga=$((mega*1024))
top -b -d 60 \
| grep --line-buffered '^.\{63\} firefox' \
| while read line ; do
echo "$line" \
| while read PID x x x x x x x percentCPU x ; do # gets run once per line
read virtual resident shared code x data x < /proc/$PID/statm
echo -n $(date '+%Y-%m-%d_%H:%M')
virtual=${virtual}p
resident=${resident}p
shared=${shared}p
code=${code}p
data=${data}p
for value in $virtual $resident $shared $percentCPU $code $data ; do
case $value in
*k ) value=$((kilo * ${value%k} )) ;;
*m ) value=$((mega * ${value%m} )) ;;
*g ) value=$(dc -e "${value%g} $giga * p") ;;
*p ) value=$(dc -e "${value%p} $page * p") ;;
* ) :
esac
echo -n " $value"
done
echo
done
done
and its partner ff-log.gnuplot :
#! /usr/bin/gnuplot -persist
# http://www.gnuplot.info/docs/gnuplot.html
# http://www.gnuplot.info/faq/faq.html
set xdata time
# 2009-06-18_17:51
set timefmt "%Y-%m-%d_%H:%M"
set format x "%m/%d\n%H:%M"
set xlabel "Time"
set xrange [ * : * ]
set ytics ("8M" 23, "16M" 24, "32M" 25, "64M" 26, "125M" 27, "256M" 28, "512M" 29, "1G" 30, "2G" 31)
set ylabel "Memory used"
set yrange [ 23 : 31 ]
set format y2 "%g%%"
set y2label "% CPU"
set y2range [ 0 : 200 ]
set key box
set key right center
set pointsize 1
set style line 1 lt rgb "orange" pt 0
set style line 2 lt rgb "red" pt 0
set style line 3 lt rgb "blue" pt 0
set style line 4 lt rgb "green" pt 0
set style line 5 lt rgb "red" pt 0
set style line 6 lt rgb "cyan" pt 0
set style line 7 lt rgb "magenta" pt 0
# 1 time
# 2 total size; Virtual
# 3 in RAM ; RSS ; Resident
# 4 Shared
# 5 % CPU
# 6 text ; code
# 7 data
# "log()"=ln(); * 1.44... converts log base e to log base 2
plot "/tmp/firefox-log.txt" using 1:(log($2) * 1.442695041) with lines title "Virtual" linestyle 1, \
"/tmp/firefox-log.txt" using 1:(log($3) * 1.442695041) with lines title "Resident" linestyle 2, \
"/tmp/firefox-log.txt" using 1:(log($2-$3) * 1.442695041) with lines title "Swapped" linestyle 3, \
"/tmp/firefox-log.txt" using 1:5 axes x1y2 with lines title "% CPU" linestyle 4, \
"/tmp/firefox-log.txt" using 1:(log($4) * 1.442695041) with lines title "Shared" linestyle 5, \
"/tmp/firefox-log.txt" using 1:(log($6) * 1.442695041) with lines title "Text (code)" linestyle 6, \
"/tmp/firefox-log.txt" using 1:(log($7) * 1.442695041) with lines title "Data" linestyle 7
I haven't figured out how to make the numbers show up on the secondary
(right) Y axis yet, but the lines are every 25.
-- -eben QebWenE01R@vTerYizUonI.nOetP http://royalty.mine.nu:81 Are you confident that you appear to be professional in your electronic communication? Consider this: A: No Q: Can I top post? from nick@xx.co.uk ----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.
This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:42:24 EDT