Add dump memory script
This commit is contained in:
parent
d0f3858646
commit
46021c22d6
|
@ -0,0 +1,42 @@
|
|||
#!/bin/sh
|
||||
|
||||
TMPFILE="/tmp/pid.txt"
|
||||
|
||||
let TOLMEM=`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`
|
||||
let FREEMEM=`cat /proc/meminfo | grep MemFree | awk '{print $2}'`
|
||||
USEDHWMEM=0
|
||||
USEDVMMEM=0
|
||||
|
||||
ps | awk '{print $1}' > $TMPFILE
|
||||
|
||||
printf "------------------------------------------------------------------------------------------------------------------\n"
|
||||
printf "| Memory(VM) = VmSize = VmLib + VmExe + VmData + VmStk |\n"
|
||||
printf "------------------------------------------------------------------------------------------------------------------\n"
|
||||
printf "| Process | PID | Memory(HW)/KB| Memory(VM)/KB| VMPeak/KB | VMLib/KB | VMStk/KB |\n"
|
||||
printf "------------------------------------------------------------------------------------------------------------------\n"
|
||||
|
||||
while read line
|
||||
do
|
||||
MEMFILE=/proc/$line/status
|
||||
|
||||
if [ -f $MEMFILE ]; then
|
||||
NAME=`cat $MEMFILE | grep Name | awk '{print $2}'`
|
||||
PID=`cat $MEMFILE | grep -w Pid | awk '{print $2}'`
|
||||
HWMEM=`cat $MEMFILE | grep VmRSS | awk '{print $2}'`
|
||||
VMMEM=`cat $MEMFILE | grep VmSize | awk '{print $2}'`
|
||||
VMPEAK=`cat $MEMFILE | grep VmPeak | awk '{print $2}'`
|
||||
VMLIB=`cat $MEMFILE | grep VmLib | awk '{print $2}'`
|
||||
VMSTK=`cat $MEMFILE | grep VmStk | awk '{print $2}'`
|
||||
|
||||
if [ -n "$HWMEM" ] && [ "$NAME" != "dump_mem.sh" ]; then
|
||||
printf "| %-24s | %-8s | %-12s | %-12s | %-12s | %-12s | %-12s |\n" " $NAME" " $PID" " $HWMEM" "$VMMEM" "$VMPEAK" "$VMLIB" "$VMSTK"
|
||||
USEDHWMEM=`expr $USEDHWMEM + $HWMEM`
|
||||
USEDVMMEM=`expr $USEDVMMEM + $VMMEM`
|
||||
fi
|
||||
fi
|
||||
done < $TMPFILE
|
||||
|
||||
printf "------------------------------------------------------------------------------------------------------------------\n"
|
||||
awk -v b=$TOLMEM -v a=$FREEMEM -v c=$USEDHWMEM -v d=$USEDVMMEM -v y=1024.0 \
|
||||
'BEGIN{printf "Used/Total(%.0fM/%.0fM): %11.2fM %11.2fM\n", (b-a)/y, b/y, c/y, d/y}'
|
||||
date -R
|
Loading…
Reference in New Issue