Chinaunix首页 | 论坛 | 博客
  • 博客访问: 371685
  • 博文数量: 43
  • 博客积分: 1493
  • 博客等级: 上尉
  • 技术积分: 660
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-01 10:57
文章分类

全部博文(43)

文章存档

2015年(1)

2013年(1)

2011年(6)

2010年(13)

2009年(13)

2008年(9)

分类: LINUX

2011-02-15 19:52:33

#!/data/busybox sh

/data/busybox mkdir -p /data/log

chmod 777 /data/log

while [ 1 == 1 ];

do

current_time=`date | /data/busybox tr -d [:[:blank:]]`;

echo "the current time is: $current_time" >>/data/log/mem_info$current_time

ps > /data/log/ps_state

processes=`cat /data/log/ps_state | /data/busybox awk '{print $2}'`

for i in $processes

do

if [ ! -e /proc/$i ];then

continue;

fi

if [ ! -e /proc/$i/status ];then

continue;

fi

process_name=`cat /proc/$i/cmdline`

echo -e "at time: "`date`" ,the process name:$process_name,pid $i, status is:\n" >> /data/log/mem_info$current_time

cat /proc/$i/status >> /data/log/mem_info$current_time

echo -e "\n" >> /data/log/mem_info$current_time

done

rm /data/log/ps_state

sleep 3600


done


内存信息都保存在了/data/log/mem_info*的文件里面,统计一次有一个这样的文件;

分析这些文件就可以看出有没有内存泄露了,可以用beyondcompare,或者再写一个脚本就可以看出哪些进程有泄漏了;

简单的分析脚本如下:
cat get_clean_info.sh 
if [ $# -lt 2 ];then
        echo "Usage $0 infile outfile"
        exit
fi
rm tmp_file tmp_name_rss
in_file=$1;
out_file=$2
cat $in_file| grep  -E 'the current|Name|Mem|Total|Swap|VmRSS'  > tmp_file
let i=0;
while read line 
do
result=`echo $line | grep -E -c "the current|Mem:|Swap:|Total:" `
if [ $result -lt 1 ];then
        is_name=`echo $line | grep -c "Name:"`
        if [ $is_name -eq 1 ];then
                name=`echo $line | awk '{print $2}'`;
                continue;
        else
                is_rss=`echo $line |grep -c "VmRSS:"`
                if [ $is_rss -eq 1 ];then
                out_line=$name"  "$line
                echo "the out_line is $out_line"
                echo "$out_line" >>tmp_name_rss
                fi
        fi
else
echo "$line" >> $out_file
fi
done < tmp_file
sleep 2
cat tmp_name_rss | sort >>$out_file

使用方法:
./get_clean_info.sh input_file output_file
对于两个样本文件执行两次这个动作,就可以看到比较简单的内存占用情况;

阅读(2612) | 评论(1) | 转发(0) |
0

上一篇:

下一篇:防止进程执行两次

给主人留下些什么吧!~~

chinaunix网友2011-03-05 16:17:41

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com