Wednesday, February 27, 2008

/proc/statm , /proc/status and top

From top

PID ... VIRT RES SHR ... COMMAND
4743 ... 2388m 722m 3532 ... java

From cat /proc/4743/status

VmSize: 2445800 kB
VmLck: 0 kB
VmRSS: 740004 kB
VmData: 2373700 kB
VmStk: 24 kB
VmExe: 72 kB
VmLib: 53241 kB
StaBrk: 00515000 kB
Brk: 00557000 kB


getconf PAGE_SIZE 4096

From cat /proc/4743/statm
611450 185001 883 18 0 593431 0

1. size :- total program size (611450 X 4096/1024 = 2445800kB = 2388M)
2. resident :- resident set size (185001 X 4096/1024 = 740004kB = 722M)
3. share :- shared pages (883 X 4096 = 3532)
4. trs :- text (code) (18 X 4096/1024 = 72kB = VmExe )
5. drs :- data/stack
6. lrs :- library (593431 X 4096/1024 = 2373724kB = VmData +VmStk)
7. dt :- dirty pages


Script to list /proc/pid/statm content


#!/bin/sh


pageSize=$(getconf PAGE_SIZE)

printf "VMSize(KB)\tReserved(KB)\tShared(KB)\tCode\tLibrary\tData/Stack\tDirty\n"

while [ 2 > 1 ]
do

vals=`cat /proc/$1/statm`

totalVM=`echo $vals $pageSize | awk '{print $1*$8/1024}'`
reserved=`echo $vals $pageSize | awk '{print $2*$8/1024}'`
shared=`echo $vals $pageSize | awk '{print $3*$8/1024}'`
code=`echo $vals $pageSize | awk '{print $4*$8/1024}'`
datastack=`echo $vals $pageSize | awk '{print $5*$8/1024}'`
library=`echo $vals $pageSize | awk '{print $6*$8/1024}'`
dirty=`echo $vals $pageSize | awk '{print $7*$8/1024}'`


printf "$totalVM\t\t$reserved\t\t$shared\t\t$code\t$datastack\t$library\t\t$dirty\n"

sleep $2

done