mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-21 22:13:19 -07:00
Add FreeBSD support to memory stat
This commit is contained in:
parent
bfb7a763d0
commit
f39446dc80
1 changed files with 34 additions and 16 deletions
|
@ -26,16 +26,32 @@ __memory_detail() {
|
||||||
__memory() {
|
__memory() {
|
||||||
local free="" total="" buffers="" cached=""
|
local free="" total="" buffers="" cached=""
|
||||||
local kb_main_used=0 buffers_plus_cached=0 fo_buffers=0 fo_cached=0
|
local kb_main_used=0 buffers_plus_cached=0 fo_buffers=0 fo_cached=0
|
||||||
|
|
||||||
if [ -r /proc/meminfo ]; then
|
if [ -r /proc/meminfo ]; then
|
||||||
while read tok val unit; do
|
if [ $(uname) != "FreeBSD"]; then
|
||||||
case "$tok" in
|
while read tok val unit; do
|
||||||
MemTotal:) total=${val};;
|
case "$tok" in
|
||||||
MemFree:) free=${val};;
|
MemTotal:) total=${val};;
|
||||||
Buffers:) buffers=${val};;
|
MemFree:) free=${val};;
|
||||||
Cached:) cached=${val};;
|
Buffers:) buffers=${val};;
|
||||||
esac
|
Cached:) cached=${val};;
|
||||||
[ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break;
|
esac
|
||||||
done < /proc/meminfo
|
[ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break;
|
||||||
|
done < /proc/meminfo
|
||||||
|
else
|
||||||
|
# FreeBSD support
|
||||||
|
page_size=$(sysctl vm.stats.vm.v_page_size | awk '{print $2'})
|
||||||
|
page_count=$(sysctl vm.stats.vm.v_page_count | awk '{print $2'})
|
||||||
|
total=$((($page_count*$page_size)/1024))
|
||||||
|
|
||||||
|
cache_pages=$(sysctl vm.stats.vm.v_cache_count | awk '{print $2'})
|
||||||
|
inact_pages=$(sysctl vm.stats.vm.v_inactive_count | awk '{print $2'})
|
||||||
|
free_pages=$(sysctl vm.stats.vm.v_free_count | awk '{print $2'})
|
||||||
|
free=$(((($cache_pages+$inact_pages+$free_pages)*$page_size)/1024))
|
||||||
|
|
||||||
|
buffers=0
|
||||||
|
cached=0
|
||||||
|
fi
|
||||||
elif eval $BYOBU_TEST vm_stat >/dev/null 2>&1; then
|
elif eval $BYOBU_TEST vm_stat >/dev/null 2>&1; then
|
||||||
# MacOS support
|
# MacOS support
|
||||||
# calculation borrowed from http://apple.stackexchange.com/a/48195/18857
|
# calculation borrowed from http://apple.stackexchange.com/a/48195/18857
|
||||||
|
@ -44,16 +60,18 @@ __memory() {
|
||||||
speculative_blocks=$(vm_stat | grep speculative | awk '{ print $3 }' | sed -e 's/\.//')
|
speculative_blocks=$(vm_stat | grep speculative | awk '{ print $3 }' | sed -e 's/\.//')
|
||||||
free=$((($free_blocks+speculative_blocks)*4))
|
free=$((($free_blocks+speculative_blocks)*4))
|
||||||
inactive=$(($inactive_blocks*4))
|
inactive=$(($inactive_blocks*4))
|
||||||
total=$((($free+$inactive)))
|
total=$(($free+$inactive))
|
||||||
buffers=0
|
buffers=0
|
||||||
cached=0
|
cached=0
|
||||||
fi
|
fi
|
||||||
kb_main_used=$(($total-$free))
|
|
||||||
buffers_plus_cached=$(($buffers+$cached))
|
kb_main_used=$(($total-$free))
|
||||||
# "free output" buffers and cache (output from 'free')
|
buffers_plus_cached=$(($buffers+$cached))
|
||||||
fo_buffers=$(($kb_main_used - $buffers_plus_cached))
|
# "free output" buffers and cache (output from 'free')
|
||||||
fpdiv $((100*${fo_buffers})) "${total}" 0;
|
fo_buffers=$(($kb_main_used - $buffers_plus_cached))
|
||||||
usage=${_RET}
|
fpdiv $((100*${fo_buffers})) "${total}" 0;
|
||||||
|
usage=${_RET}
|
||||||
|
|
||||||
if [ $total -ge 1048576 ]; then
|
if [ $total -ge 1048576 ]; then
|
||||||
fpdiv "$total" 1048567 1
|
fpdiv "$total" 1048567 1
|
||||||
total=${_RET}
|
total=${_RET}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue