Lines 1-11
Link Here
|
1 |
--- usr/lib/byobu/memory.orig 2019-08-23 17:23:09 UTC |
1 |
--- usr/lib/byobu/memory.orig 2016-09-15 19:22:48 UTC |
2 |
+++ usr/lib/byobu/memory |
2 |
+++ usr/lib/byobu/memory |
3 |
@@ -52,7 +52,7 @@ __memory() { |
3 |
@@ -26,16 +26,35 @@ __memory_detail() { |
4 |
buffers_plus_cached=$(($buffers+$cached)) |
4 |
__memory() { |
5 |
# "free output" buffers and cache (output from 'free') |
5 |
local free="" total="" buffers="" cached="" |
6 |
fo_buffers=$(($kb_main_used - $buffers_plus_cached)) |
6 |
local kb_main_used=0 buffers_plus_cached=0 fo_buffers=0 fo_cached=0 |
|
|
7 |
- if [ -r /proc/meminfo ]; then |
8 |
- while read tok val unit; do |
9 |
- case "$tok" in |
10 |
- MemTotal:) total=${val};; |
11 |
- MemFree:) free=${val};; |
12 |
- Buffers:) buffers=${val};; |
13 |
- Cached:) cached=${val};; |
14 |
- esac |
15 |
- [ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break; |
16 |
- done < /proc/meminfo |
17 |
+ |
18 |
+ if [ $(uname) = "Linux" ]; then |
19 |
+ if [ -r /proc/meminfo ]; then |
20 |
+ while read tok val unit; do |
21 |
+ case "$tok" in |
22 |
+ MemTotal:) total=${val};; |
23 |
+ MemFree:) free=${val};; |
24 |
+ Buffers:) buffers=${val};; |
25 |
+ Cached:) cached=${val};; |
26 |
+ esac |
27 |
+ [ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break; |
28 |
+ done < /proc/meminfo |
29 |
+ fi |
30 |
+ elif [ $(uname) = "FreeBSD" ]; then |
31 |
+ # FreeBSD support |
32 |
+ mem_phys=$(sysctl -n hw.physmem) |
33 |
+ page_size=$(sysctl -n hw.pagesize) |
34 |
+ mem_inactive=$(($(sysctl -n vm.stats.vm.v_inactive_count)*$page_size)) |
35 |
+ mem_cache=$(($(sysctl -n vm.stats.vm.v_cache_count)*$page_size)) |
36 |
+ mem_free=$(($(sysctl -n vm.stats.vm.v_free_count)*$page_size)) |
37 |
+ |
38 |
+ mem_avail=$(($mem_inactive+$mem_cache+$mem_free)) |
39 |
+ mem_used=$(($mem_phys-$mem_avail)) |
40 |
+ |
41 |
+ total=$(($mem_phys/1024)) |
42 |
+ free=$(($mem_avail/1024)) |
43 |
+ |
44 |
+ buffers=0 |
45 |
+ cached=0 |
46 |
elif eval $BYOBU_TEST vm_stat >/dev/null 2>&1; then |
47 |
# MacOS support |
48 |
# calculation borrowed from http://apple.stackexchange.com/a/48195/18857 |
49 |
@@ -44,16 +63,18 @@ __memory() { |
50 |
speculative_blocks=$(vm_stat | grep speculative | awk '{ print $3 }' | sed -e 's/\.//') |
51 |
free=$((($free_blocks+speculative_blocks)*4)) |
52 |
inactive=$(($inactive_blocks*4)) |
53 |
- total=$((($free+$inactive))) |
54 |
+ total=$(($free+$inactive)) |
55 |
buffers=0 |
56 |
cached=0 |
57 |
fi |
58 |
- kb_main_used=$(($total-$free)) |
59 |
- buffers_plus_cached=$(($buffers+$cached)) |
60 |
- # "free output" buffers and cache (output from 'free') |
61 |
- fo_buffers=$(($kb_main_used - $buffers_plus_cached)) |
7 |
- fpdiv $((100*${fo_buffers})) "${total}" 0; |
62 |
- fpdiv $((100*${fo_buffers})) "${total}" 0; |
8 |
+ fpdiv $((100*${kb_main_used})) "${total}" 0; |
63 |
- usage=${_RET} |
9 |
usage=${_RET} |
64 |
+ |
|
|
65 |
+ kb_main_used=$(($total-$free)) |
66 |
+ buffers_plus_cached=$(($buffers+$cached)) |
67 |
+ # "free output" buffers and cache (output from 'free') |
68 |
+ fo_buffers=$(($kb_main_used - $buffers_plus_cached)) |
69 |
+ fpdiv $((100*${fo_buffers})) "${total}" 0; |
70 |
+ usage=${_RET} |
71 |
+ |
10 |
if [ $total -ge 1048576 ]; then |
72 |
if [ $total -ge 1048576 ]; then |
11 |
fpdiv "$total" 1048567 1 |
73 |
fpdiv "$total" 1048567 1 |
|
|
74 |
total=${_RET} |
75 |
@@ -74,5 +95,3 @@ __memory() { |
76 |
[ -n "$total" ] || return |
77 |
color b g W; printf "%s" "$total"; color -; color g W; printf "%s" "$unit"; color -; color b g "$fg"; printf "%s" "$usage"; color -; color g "$fg"; printf "%s" "$PCT"; color -- |
78 |
} |
79 |
- |
80 |
-# vi: syntax=sh ts=4 noexpandtab |