From 46021c22d6997d6e64a01c3c31469f1d9378adca Mon Sep 17 00:00:00 2001 From: HuangXin Date: Fri, 11 Jan 2019 16:01:34 +0800 Subject: [PATCH] Add dump memory script --- package/base-files/files/bin/dump_mem.sh | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 package/base-files/files/bin/dump_mem.sh diff --git a/package/base-files/files/bin/dump_mem.sh b/package/base-files/files/bin/dump_mem.sh new file mode 100755 index 000000000..536d66d8d --- /dev/null +++ b/package/base-files/files/bin/dump_mem.sh @@ -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