用于整理smaps信息的脚本
Charles Chan @ 2017-10-29 #Memory #smaps @Linux
Contents:
将线性的输出信息整理成为二维的表格,便于查看。
脚本中的数字15是每一个项目包含的行数,可能需要根据实际情况进行调整。
#!/bin/bash
install -d /tmp/smaps.csv
cd /proc/
for i in `ls -1`
do
if [ -f /proc/$i/smaps ] ; then
cat /proc/$i/smaps | awk 'BEGIN{i=0}{line[i]=$0;gsub(": ",",",line[i]);gsub(" kB", "", line[i]);i++;if(i>15){for(j=0;j<i;j++){printf("%s,",line[j])}printf("\n");i=0}}' > /tmp/smaps.csv/$i.smap.csv
fi
done
echo ,RL,RSS,PSS,SC,SD,PC,PD,REF,ANON,AHP, > /tmp/smaps.csv/smaps.calc.csv.tmp
cd /tmp/smaps.csv/
for i in `ls -1 *.csv`
do
awk -v f=$i 'BEGIN{FS=","}
{
if($5 == $7) {
rl+=$5;
}
pss+=$7;rss+=$5;sc+=$9;sd+=$11;pc+=$13;pd+=$15;ref+=$17;anon+=$19;ahp+=$21;
}
END{
printf("%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\n", f, rl, rss, pss, sc, sd, pc, pd, ref, anon, ahp)
}' $i >> /tmp/smaps.csv/smaps.calc.csv.tmp
done
mv /tmp/smaps.csv/smaps.calc.csv.tmp /tmp/smaps.csv/smaps.calc.csv
awk 'BEGIN{FS=","}{rl+=$2;rss+=$3;pss+=$4}END{print rl" "rss" "pss}' /tmp/smaps.csv/smaps.calc.csv