summaryrefslogtreecommitdiff
path: root/rc/bin/memory
diff options
context:
space:
mode:
authoraiju <aiju@phicode.de>2011-07-23 16:05:37 +0200
committeraiju <aiju@phicode.de>2011-07-23 16:05:37 +0200
commitfe97c2dd85040689c9d665e15f3d8baf8c853b9d (patch)
treed440e60ca8d8a0cf78255fc6efc63e490e25af69 /rc/bin/memory
parent18e6824756e39575004cec83229880120b86fc4a (diff)
downloadplan9front-fe97c2dd85040689c9d665e15f3d8baf8c853b9d.tar.xz
added memory(1)
Diffstat (limited to 'rc/bin/memory')
-rwxr-xr-xrc/bin/memory16
1 files changed, 16 insertions, 0 deletions
diff --git a/rc/bin/memory b/rc/bin/memory
new file mode 100755
index 000000000..35ad94d44
--- /dev/null
+++ b/rc/bin/memory
@@ -0,0 +1,16 @@
+#!/bin/rc
+awk '
+function human(name, n) {
+ printf "%-15s", name
+ if(n >= 1000000000) printf "%.3g GB\n", n / 1073741824
+ else if(n >= 1000000) printf "%.3g MB\n", n / 1048576
+ else if(n >= 1000) printf "%.3g KB\n", n / 1024
+ else printf "%d B\n", n
+}
+$2 == "memory" { human("total", $1) }
+$2 == "pagesize" { pagesize = $1 }
+$2 == "kernel" && NF == 2 { human("total kernel", $1 * pagesize) }
+$2 == "user" { split($1, a, "/"); human("total user", a[2] * pagesize); print ""; human("used user", a[1] * pagesize) }
+$2 == "kernel" && $3 == "malloc" { split($1, a, "/"); human("used kernel", a[1]) }
+$2 == "kernel" && $3 == "draw" { split($1, a, "/"); human("used draw", a[1]) }
+' < /dev/swap