a script to get mem usage based on both smaps and statm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
sum_smap_rs_pd() { | |
awk '/^Private_Dirty:/ { p += $2 } | |
/^Rss:/ { s += $2 } | |
END { print s,p }' /proc/$1/smaps 2> /dev/null | |
} | |
sum_statm_rs_data() { | |
awk '{ print $2*4,$6*4 }' /proc/$1/statm 2> /dev/null | |
} | |
stats() { | |
smap=$(sum_smap_rs_pd $1) | |
statm=$(sum_statm_rs_data $1) | |
name=$(cat /proc/$1/comm | tr ' ' '_') 2> /dev/null | |
if [ X$name = X ]; then | |
name=unknown | |
smap="0 0" | |
statm="0 0" | |
fi | |
line=$(printf "%d\t%20s%12s%12d%12d%12d\n" $1 "$name" $smap $statm) | |
if [ $? -ne 0 ]; then | |
cat /proc/$1/smaps | |
cat /proc/$1/statm | |
exit 1 | |
fi | |
echo "$line" | (read id n a b c d | |
if [ $b -gt $d ]]; then echo "$line" "dirty private pages > data"; else echo "$line"; fi | |
) | |
} | |
printf "%s\t%20s%12s%12s%12s%12s\n" id name smap_rs smap_pd statm_rs statm_data | |
if [ X$1 = "X" ]; then | |
for i in $(ps --no-headers -Ao pid) | |
do | |
stats $i | |
done | |
else | |
stats $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment