Plan 9 from Bell Labs’s /usr/web/sources/contrib/andrey/mem

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc

all=`{cat /dev/swap | tr  '
/' ' '}

total = $all(1)
pagesize = $all(3)
kernel = $all(5)
userused = $all(7)
usertotal = $all(8)
swapused = $all(10)
swaptotal = $all(11)
mallocused = $all(13)
malloctotal = $all(14)
drawused = $all(17)
drawtotal = $all(18)

pageinmb = `{echo $pagesize^'/(1024*1024)' | hoc }

userused = `{echo 'int('^$userused^'*'^$pageinmb^')' | hoc }
usertotal = `{echo 'int('^$usertotal^'*'^$pageinmb^')' | hoc}
userperc = 0
if(! ~ $userused 0){
	userperc = `{echo 'int('^$userused^'*100/'^$usertotal^')' | hoc}
}

swapused = `{echo 'int('^$swapused^'*'^$pageinmb^')' | hoc }
swaptotal = `{echo 'int('^$swaptotal^'*'^$pageinmb^')' | hoc}
swapperc = 0
if(! ~ $swapused 0){
	swapperc = `{echo 'int('^$swapused^'*100/'^$swaptotal^')' | hoc}
}

mallocused = `{echo 'int('^$mallocused^'*'^$pageinmb^')' | hoc }
malloctotal = `{echo 'int('^$malloctotal^'*'^$pageinmb^')' | hoc}
mallocperc = 0
if(! ~ $mallocused 0){
	mallocperc = `{echo 'int('^$mallocused^'*100/'^$malloctotal^')' | hoc}
}

drawused = `{echo 'int('^$drawused^'*'^$pageinmb^')' | hoc }
drawtotal = `{echo 'int('^$drawtotal^'*'^$pageinmb^')' | hoc}
drawperc = 0
if(! ~ $drawused 0){
	drawperc = `{echo 'int('^$drawused^'*100/'^$drawtotal^')' | hoc}
}

echo 'user:	'^$userused^' MB used ('^$userperc^'% of '^$usertotal^' MB).'
echo 'swap:	'^$swapused^' MB used ('^$swapperc^'% of '^$swaptotal^' MB).'
echo 'malloc:	'^$mallocused^' MB used ('^$mallocperc^'% of '^$malloctotal^' MB).'
echo 'draw:	'^$drawused^' MB used ('^$drawperc^'% of '^$drawtotal^' MB).'


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].