@@ -11,17 +11,10 @@ mem_view_tmpl=$(get_tmux_option "@sysstat_mem_view_tmpl" '#[fg=#{mem.color}]#{me
1111mem_medium_threshold=$( get_tmux_option " @sysstat_mem_medium_threshold" " 75" )
1212mem_stress_threshold=$( get_tmux_option " @sysstat_mem_stress_threshold" " 90" )
1313
14- swap_medium_threshold=$( get_tmux_option " @sysstat_swap_medium_threshold" " 25" )
15- swap_stress_threshold=$( get_tmux_option " @sysstat_swap_stress_threshold" " 75" )
16-
1714mem_color_low=$( get_tmux_option " @sysstat_mem_color_low" " green" )
1815mem_color_medium=$( get_tmux_option " @sysstat_mem_color_medium" " yellow" )
1916mem_color_stress=$( get_tmux_option " @sysstat_mem_color_stress" " red" )
2017
21- swap_color_low=$( get_tmux_option " @sysstat_swap_color_low" " green" )
22- swap_color_medium=$( get_tmux_option " @sysstat_swap_color_medium" " yellow" )
23- swap_color_stress=$( get_tmux_option " @sysstat_swap_color_stress" " red" )
24-
2518size_unit=$( get_tmux_option " @sysstat_mem_size_unit" " G" )
2619
2720get_mem_color () {
@@ -36,18 +29,6 @@ get_mem_color() {
3629 fi
3730}
3831
39- get_swap_color () {
40- local swap_pused=$1
41-
42- if fcomp " $swap_stress_threshold " " $swap_pused " ; then
43- echo " $swap_color_stress " ;
44- elif fcomp " $swap_medium_threshold " " $swap_pused " ; then
45- echo " $swap_color_medium " ;
46- else
47- echo " $swap_color_low " ;
48- fi
49- }
50-
5132print_mem () {
5233 local mem_usage
5334 local scale
@@ -59,43 +40,18 @@ print_mem() {
5940 mem_usage=$( get_mem_usage_linux)
6041 fi
6142
62- # get_mem_usage* function returns values in KiB
63- # 1 - scale to KiB
64- # 1024 - scale to MiB
65- # 1048576 - scale to GiB
66- case " $size_unit " in
67- G) scale=1048576;;
68- M) scale=1024;;
69- K) scale=1;;
70- esac
71-
72- # Depending on scale factor, change precision
73- # 12612325K - no digits after floating point
74- # 1261M - no digits after floating point
75- # 1.1G - 1 digit after floating point
76- case " $size_unit " in
77- G) size_format=' %.1f%s' ;;
78- M) size_format=' %.0f%s' ;;
79- K) size_format=' %.0f%s' ;;
80- esac
43+ local size_scale=" $( get_size_scale_factor " $size_unit " ) "
44+ local size_format=" $( get_size_format " $size_unit " ) "
8145
8246 # Extract free and used memory in MiB, calculate total and percentage
83- local mem_free=$( echo $mem_usage | awk -v scale=" $scale " ' { print $1/scale }' )
84- local mem_used=$( echo $mem_usage | awk -v scale=" $scale " ' { print $2/scale }' )
47+ local mem_free=$( echo $mem_usage | awk -v scale=" $size_scale " ' { print $1/scale }' )
48+ local mem_used=$( echo $mem_usage | awk -v scale=" $size_scale " ' { print $2/scale }' )
8549 local mem_total=$( echo " $mem_free + $mem_used " | calc)
8650 local mem_pused=$( echo " ($mem_used / $mem_total ) * 100" | calc)
8751 local mem_pfree=$( echo " ($mem_free / $mem_total ) * 100" | calc)
88-
89- # Extract swap free and used in MiB, calculate total and percentage
90- local swap_free=$( echo $mem_usage | awk -v scale=" $scale " ' { print $3/scale }' )
91- local swap_used=$( echo $mem_usage | awk -v scale=" $scale " ' { print $4/scale }' )
92- local swap_total=$( echo " $swap_free + $swap_used " | calc)
93- local swap_pused=$( echo " ($swap_used / $swap_total ) * 100" | calc)
94- local swap_pfree=$( echo " ($swap_free / $swap_total ) * 100" | calc)
9552
9653 # Calculate colors for mem and swap
9754 local mem_color=$( get_mem_color " $mem_pused " )
98- local swap_color=$( get_swap_color " $swap_pused " )
9955
10056 local mem_view=" $mem_view_tmpl "
10157 mem_view=" ${mem_view// ' #{mem.used}' / $(printf " $size_format " " $mem_used " " $size_unit " )} "
@@ -106,15 +62,6 @@ print_mem() {
10662 mem_view=" ${mem_view// ' #{mem.color}' / $(echo " $mem_color " | awk ' { print $1 }' )} "
10763 mem_view=" ${mem_view// ' #{mem.color2}' / $(echo " $mem_color " | awk ' { print $2 }' )} "
10864 mem_view=" ${mem_view// ' #{mem.color3}' / $(echo " $mem_color " | awk ' { print $3 }' )} "
109-
110- mem_view=" ${mem_view// ' #{swap.used}' / $(printf " $size_format " " $swap_used " " $size_unit " )} "
111- mem_view=" ${mem_view// ' #{swap.pused}' / $(printf " %.0f%%" " $swap_pused " )} "
112- mem_view=" ${mem_view// ' #{swap.free}' / $(printf " $size_format " " $swap_free " " $size_unit " )} "
113- mem_view=" ${mem_view// ' #{swap.pfree}' / $(printf " %.0f%%" " $swap_pfree " )} "
114- mem_view=" ${mem_view// ' #{swap.total}' / $(printf " $size_format " " $swap_total " " $size_unit " )} "
115- mem_view=" ${mem_view// ' #{swap.color}' / $(echo " $swap_color " | awk ' { print $1 }' )} "
116- mem_view=" ${mem_view// ' #{swap.color2}' / $(echo " $swap_color " | awk ' { print $2 }' )} "
117- mem_view=" ${mem_view// ' #{swap.color3}' / $(echo " $swap_color " | awk ' { print $3 }' )} "
11865
11966 echo " $mem_view "
12067}
@@ -127,7 +74,7 @@ print_mem() {
12774get_mem_usage_osx (){
12875
12976 local page_size=$( sysctl -nq " vm.pagesize" )
130- local free_used= $( vm_stat | awk -v page_size=$page_size -F ' :' '
77+ vm_stat | awk -v page_size=$page_size -F ' :' '
13178 BEGIN { free=0; used=0 }
13279
13380 /Pages active/ ||
@@ -142,13 +89,7 @@ get_mem_usage_osx(){
14289 }
14390
14491 END { print (free * page_size)/1024, (used * page_size)/1024 }
145- ' )
146-
147- # assume swap size in MB
148- local swap_used=$( sysctl -nq vm.swapusage | awk -F ' ' ' { print $2 }' | awk -F ' =' ' {gsub(/^[ ]|[M]$/, "", $2); printf "%d", $2 * 1024 }' )
149- local swap_free=$( sysctl -nq vm.swapusage | awk -F ' ' ' { print $3 }' | awk -F ' =' ' {gsub(/^[ ]|[M]$/, "", $2); printf "%d", $2 * 1024 }' )
150-
151- printf " %s %s %s" " $free_used " " $swap_free " " $swap_used "
92+ '
15293}
15394
15495
@@ -160,7 +101,7 @@ get_mem_usage_osx(){
160101
161102# See: kernel/git/torvalds/linux.git - /proc/meminfo: provide estimated available memory - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773
162103get_mem_usage_linux (){
163- local mem_free_used= $( < /proc/meminfo awk '
104+ < /proc/meminfo awk '
164105 BEGIN { total=0; free=0; }
165106 /MemTotal:/ { total=$2; }
166107
@@ -170,16 +111,7 @@ get_mem_usage_linux(){
170111
171112 /MemAvailable:/ { free=$2; exit;}
172113 END { print free, total-free }
173- ' )
174-
175- local swap_free_used=$( < /proc/meminfo awk '
176- BEGIN { total=0; free=0; }
177- /SwapTotal:/ { total=$2; }
178- /SwapFree:/ { free=$2; }
179- END { print free, total-free }
180- ' )
181-
182- printf " %s %s" " $mem_free_used " " $swap_free_used "
114+ '
183115}
184116
185117main () {
0 commit comments