Merge lp:~smoser/byobu/status-speedups into lp:byobu

Proposed by Scott Moser
Status: Merged
Merged at revision: 1382
Proposed branch: lp:~smoser/byobu/status-speedups
Merge into: lp:byobu
Diff against target: 1000 lines (+421/-231)
23 files modified
usr/bin/byobu (+1/-1)
usr/bin/byobu-reconnect-sockets (+1/-1)
usr/bin/byobu-status (+5/-12)
usr/lib/byobu/.shutil (+54/-0)
usr/lib/byobu/battery (+53/-51)
usr/lib/byobu/cpu_freq (+3/-1)
usr/lib/byobu/cpu_temp (+2/-2)
usr/lib/byobu/custom (+10/-7)
usr/lib/byobu/date (+4/-2)
usr/lib/byobu/disk (+21/-4)
usr/lib/byobu/disk_io (+26/-12)
usr/lib/byobu/fan_speed (+28/-18)
usr/lib/byobu/ip_address (+4/-2)
usr/lib/byobu/load_average (+2/-2)
usr/lib/byobu/mem_available (+23/-16)
usr/lib/byobu/mem_used (+37/-1)
usr/lib/byobu/network (+19/-13)
usr/lib/byobu/raid (+11/-9)
usr/lib/byobu/release (+50/-41)
usr/lib/byobu/swap (+37/-16)
usr/lib/byobu/updates_available (+10/-10)
usr/lib/byobu/uptime (+7/-5)
usr/lib/byobu/wifi_quality (+13/-5)
To merge this branch: bzr merge lp:~smoser/byobu/status-speedups
Reviewer Review Type Date Requested Status
Dustin Kirkland  Pending
Review via email: mp+61172@code.launchpad.net

Description of the change

Several speed improvements.
You should probably consider the disk_io and network not all that tested.

I'd like for you to test and see what you find.

I'm fairly happy with the state as of 1384 and have done some moderate
usage testing. for 'byobu true', I'm seeing a reduction on my system
from ~ 0.33 to ~ 0.22. Over 100 runs I saw:
  trunk (rev. 1381):
    real 0m33.576s
    user 0m0.080s
    sys 0m0.050s
  branch (rev. 1387):
    real 0m22.771s
    user 0m0.030s
    sys 0m0.030s

To post a comment you must log in.
Revision history for this message
Dustin Kirkland  (kirkland) wrote :

Sweet, thanks, Scott.

Just checking ...

Have you found this yet?
 * ./usr/share/byobu/tests/byobu-time-notifications

I'm on holiday right now, but will merge and upload your change this
weekend. I'll grab your branch and test the heck out of it on the
flights back home. Thanks again, dude!

Revision history for this message
Scott Moser (smoser) wrote :

On Wed, 18 May 2011, Dustin Kirkland wrote:

> Sweet, thanks, Scott.
>
> Just checking ...
>
> Have you found this yet?
> * ./usr/share/byobu/tests/byobu-time-notifications
>
> I'm on holiday right now, but will merge and upload your change this
> weekend. I'll grab your branch and test the heck out of it on the
> flights back home. Thanks again, dude!

I had not seen it. Heres an edited list of the stuff I changed.

apport 0.155 | 0.145
battery 2.563 | 0.219
cpu_freq 0.503 | 0.154
cpu_temp 1.167 | 0.215
custom 1.054 | 0.219
date 0.345 | 0.224
disk 1.678 | 0.648
disk_io 1.705 | 0.499
fan_speed 0.728 | 0.188
ip_address 0.789 | 0.801
load_average 0.519 | 0.141
mem_available 1.091 | 0.170
network 1.069 | 0.562
raid 0.927 | 0.139
release 1.093 | 0.158
swap 1.668 | 0.182
updates_available 0.661 | 0.505
uptime 0.873 | 0.146
wifi_quality 2.066 | 0.748

sm

Revision history for this message
Dustin Kirkland  (kirkland) wrote :

Committed/pushed. Thanks!

lp:~smoser/byobu/status-speedups updated
1382. By Dustin Kirkland 

speedups from scott

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'usr/bin/byobu'
2--- usr/bin/byobu 2011-05-15 21:03:29 +0000
3+++ usr/bin/byobu 2011-05-18 18:29:02 +0000
4@@ -25,7 +25,7 @@
5 RUN="$SOCKETDIR/S-$USER"
6 DATA="$HOME/.$PKG"
7
8-. "${BYOBU_PREFIX}/usr/lib/${PKG}/.shutil"
9+. "${BYOBU_PREFIX}/lib/${PKG}/.shutil"
10 if [ ! -x "$BYOBU_PREFIX/bin/$PKG" ]; then
11 error "Cannot find $BYOBU_PREFIX/bin/$PKG"
12 error "If you have installed it elsewhere, export BYOBU_PREFIX in your shell"
13
14=== modified file 'usr/bin/byobu-reconnect-sockets'
15--- usr/bin/byobu-reconnect-sockets 2011-05-15 21:03:29 +0000
16+++ usr/bin/byobu-reconnect-sockets 2011-05-18 18:29:02 +0000
17@@ -23,7 +23,7 @@
18
19 PKG="byobu"
20
21-. "${BYOBU_PREFIX}/usr/lib/${PKG}/.shutil"
22+. "${BYOBU_PREFIX}/lib/${PKG}/.shutil"
23
24 case "$-" in
25 *i*)
26
27=== modified file 'usr/bin/byobu-status'
28--- usr/bin/byobu-status 2011-05-13 14:26:22 +0000
29+++ usr/bin/byobu-status 2011-05-18 18:29:02 +0000
30@@ -21,18 +21,11 @@
31 DATA="$HOME/.$PKG"
32 [ -z "$BYOBU_PREFIX" ] && export BYOBU_PREFIX="/usr" || export BYOBU_PREFIX
33
34-find_script () {
35- # Allow for local status scripts
36- if [ -x "$DATA/bin/$1" ]; then
37- _RET="$DATA/bin/$1"
38- elif [ -x "$BYOBU_PREFIX/lib/$PKG/$1" ]; then
39- _RET="$BYOBU_PREFIX/lib/$PKG/$1"
40- elif [ -x "$BYOBU_PREFIX/libexec/$PKG/$1" ]; then
41- _RET="$BYOBU_PREFIX/libexec/$PKG/$1"
42- else
43- _RET="/dev/null"
44- fi
45-}
46+if ! . "${BYOBU_PREFIX}/lib/${PKG}/.shutil"; then
47+ echo "failed to source ${BYOBU_PREFIX}/lib/${PKG}/.shutil" 2>&1
48+ echo "If you have installed elsewhere, export BYOBU_PREFIX in your shell" 2>&1
49+ exit 1
50+fi
51
52 # Define colors
53 ESC="\005"
54
55=== modified file 'usr/lib/byobu/.shutil'
56--- usr/lib/byobu/.shutil 2011-05-15 21:03:29 +0000
57+++ usr/lib/byobu/.shutil 2011-05-18 18:29:02 +0000
58@@ -23,3 +23,57 @@
59 fail() {
60 [ $# -eq 0 ] || error "$@"; exit 1;
61 }
62+
63+find_script() {
64+ # Allow for local status scripts
65+ if [ -x "$DATA/bin/$1" ]; then
66+ _RET="$DATA/bin/$1"
67+ elif [ -x "$BYOBU_PREFIX/lib/$PKG/$1" ]; then
68+ _RET="$BYOBU_PREFIX/lib/$PKG/$1"
69+ elif [ -x "$BYOBU_PREFIX/libexec/$PKG/$1" ]; then
70+ _RET="$BYOBU_PREFIX/libexec/$PKG/$1"
71+ else
72+ _RET="/dev/null"
73+ fi
74+}
75+
76+# divide 2 integers and return a floating point number
77+# third argument indicates how many digits after the decimal
78+fpdiv() {
79+ local a=$1 b=$2 pres=${3:-3}
80+ local i=0 mp="10" whole="" part=""
81+ while i=$(($i+1)) && [ $i -le $pres ]; do
82+ mp="${mp}0"
83+ done
84+ whole=$(($a/$b))
85+ part=$((((($a%$b)*${mp})/$b)))
86+ if [ $part -eq 0 ]; then
87+ part=${part#1};
88+ elif [ $((${part}%(${mp}/10))) -ge 5 ]; then
89+ part=$(($part+5))
90+ fi
91+ _RET="${whole}.${part%?}"
92+}
93+
94+# rtrim(string,chars)
95+rtrim() {
96+ local tab=' ' cr="
97+"
98+ local cur="${1}" set="[${2:- ${tab}${cr}}]" n=""
99+ while n=${cur%${set}} && [ "$n" != "$cur" ]; do cur=${n}; done
100+ _RET=${cur}
101+}
102+
103+readfile() {
104+ local c="" r="" cr="
105+"
106+ OIFS="$IFS"; IFS="";
107+ while read c; do
108+ r="$r${cr}$c"
109+ done
110+ IFS=$OIFS
111+ _RET=${r}
112+ return 0
113+}
114+
115+# vi: syntax=sh ts=4 noexpandtab
116
117=== modified file 'usr/lib/byobu/battery'
118--- usr/lib/byobu/battery 2011-05-13 14:26:22 +0000
119+++ usr/lib/byobu/battery 2011-05-18 18:29:02 +0000
120@@ -21,14 +21,6 @@
121 PKG="byobu"
122 color 2>/dev/null || color() { true; }
123
124-search () {
125- local str expr
126- str="$1"
127- expr="$2"
128- echo "$str" | sed -n "s/${expr}/\1/p"
129-}
130-
131-
132 if [ "$1" = "--detail" ]; then
133 for bat in /proc/acpi/battery/*; do
134 cat "$bat/info"
135@@ -37,46 +29,56 @@
136 exit 0
137 fi
138
139-for bat in $BATTERY /proc/acpi/battery/*; do
140- # make sure that this battery is present
141- infofile=$(cat "$bat/info")
142- present=$(search "$infofile" "present: *\(.*\)")
143- [ "${present}" = "no" ] && continue
144-
145- # obtain full and remaining battery values
146- statefile=$(cat "$bat/state")
147- full=$(search "$infofile" "last full capacity: *\(.*\) m[AW]h")
148- rem=$(search "$statefile" "remaining capacity: *\(.*\) m[AW]h")
149-
150- percent=$( echo "$rem" "$full" | awk '{printf "%.0f", 100*$1/$2}')
151- if [ "$percent" -lt 33 ]; then
152- color="R k"
153- bcolor="b R k"
154- elif [ "$percent" -lt 67 ]; then
155- color="Y k"
156- bcolor="b Y k"
157- else
158- color="G k"
159- bcolor="b G k"
160- fi
161- percent="$percent%"
162-
163- state=$(search "$statefile" "charging state: *\(.*\)")
164- case $state in
165- charging)
166- sign="+"
167- ;;
168- discharging)
169- sign="-"
170- ;;
171- charged)
172- sign="="
173- percent=
174- ;;
175- *)
176- sign="$state"
177- ;;
178- esac
179- color $bcolor; printf "%s" "$percent"; color -; color $color; printf "|%s|" "$sign"; color --
180- break
181-done
182+battery_info() {
183+ local bat line present sign state percent full rem color bcolor
184+ for bat in $BATTERY /proc/acpi/battery/*; do
185+ [ -f "$bat/info" ] || continue
186+
187+ present=""; full=""; rem=""; state=""
188+ while read line; do
189+ set -- ${line}
190+ case "$line" in
191+ present:*)
192+ # make sure that this battery is present
193+ [ "$2" = "no" ] && continue 2
194+ present="$2";;
195+ last\ full\ capacity:*) full="$4";;
196+ esac
197+ [ -n "$present" -a -n "$full" ] && break
198+ done < "${bat}/info"
199+
200+ while read line; do
201+ set -- ${line}
202+ case "$line" in
203+ remaining\ capacity:*) rem="$3";;
204+ charging\ state:*) state="$3";;
205+ esac
206+ [ -n "$rem" -a -n "$state" ] && break
207+ done < "$bat/state"
208+
209+ percent=$(((100*$rem)/$full))
210+
211+ if [ "$percent" -lt 33 ]; then
212+ color="R k"
213+ bcolor="b R k"
214+ elif [ "$percent" -lt 67 ]; then
215+ color="Y k"
216+ bcolor="b Y k"
217+ else
218+ color="G k"
219+ bcolor="b G k"
220+ fi
221+ percent="$percent%"
222+
223+ case $state in
224+ charging) sign="+" ;;
225+ discharging) sign="-" ;;
226+ charged) sign="="; percent="" ;;
227+ *) sign="$state" ;;
228+ esac
229+ color $bcolor; printf "%s" "$percent"; color -; color $color; printf "|%s|" "$sign"; color --
230+ break
231+ done
232+}
233+
234+battery_info "$@"
235
236=== modified file 'usr/lib/byobu/cpu_freq'
237--- usr/lib/byobu/cpu_freq 2011-05-13 14:26:22 +0000
238+++ usr/lib/byobu/cpu_freq 2011-05-18 18:29:02 +0000
239@@ -26,7 +26,9 @@
240 fi
241
242 if [ -r "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" ]; then
243- freq=$(awk '{ printf "%.1f", $1 / 1000000 }' /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)
244+ read hz < /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
245+ fpdiv $hz "1000000" 1 # 1Ghz
246+ freq="$_RET"
247 else
248 if egrep -q -s -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo; then
249 freq=$(egrep -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo | awk -F"[:.]" '{ printf "%.1f", $2 / 1000 }')
250
251=== modified file 'usr/lib/byobu/cpu_temp'
252--- usr/lib/byobu/cpu_temp 2011-05-13 14:26:22 +0000
253+++ usr/lib/byobu/cpu_temp 2011-05-18 18:29:02 +0000
254@@ -36,7 +36,7 @@
255 for i in $MONITORED_TEMP /sys/class/hwmon/hwmon*/temp*_input /proc/acpi/ibm/thermal $DIR/*/temperature; do
256 case "$i" in
257 *temp*_input)
258- [ -s "$i" ] && t=$(awk '{printf "%0.f",$1/1000}' "$i")
259+ [ -s "$i" ] && read t < "$i" && t=$(($t/1000))
260 ;;
261 *)
262 [ -s "$i" ] && t=$(sed -e "s/^[^0-9]\+//" -e "s/\s.*$//" "$i")
263@@ -45,7 +45,7 @@
264 if [ -n "$t" ]; then
265 unit="$ICON_C"
266 if [ "$TEMP" = "F" ]; then
267- t=$(echo "$t" | awk '{printf "%.0f", $1 *9/5 + 32}')
268+ t=$(($t*9/5 + 32))
269 unit="$ICON_F"
270 fi
271 color b k Y; printf "%s" "$t"; color -; color k Y; printf "%s%s" "$ICON" "$unit"; color --
272
273=== modified file 'usr/lib/byobu/custom'
274--- usr/lib/byobu/custom 2011-05-13 14:26:22 +0000
275+++ usr/lib/byobu/custom 2011-05-18 18:29:02 +0000
276@@ -30,15 +30,18 @@
277 # Loop over custom scripts
278 for i in "$DATA/bin/"[0-9]*_*; do
279 [ -x "$i" ] || continue
280- script=$(basename "$i")
281- freq=$(echo "$script" | awk -F_ '{print $1}')
282- lastrun=$(stat -c %Y "$CACHE.$script") 2>/dev/null || lastrun=0
283- expiration=$(expr $lastrun + $freq)
284+ script=${script##*/}
285+ freq=${script%%_*}
286+ freq=${freq#0}
287+ [ -r "$CACHE.$script.last" ] && read lastrun "$CACHE.$script.last" ||
288+ lastrun=0
289+ expiration=$(($lastrun+$freq))
290 if [ $NOW -ge $expiration ]; then
291- # Update the cache
292- $i $@ > "$CACHE.$script" 2>/dev/null
293+ "$i" "$@" > "$CACHE.$script" 2>/dev/null
294+ echo "${NOW}" > "$CACHE.$script.last"
295 fi
296- output=$(cat "$CACHE.$script")
297+ readfile < "$CACHE.$script"
298+ output="${_RET}"
299 case "$output" in
300 *"$ESC{"*)
301 # User has formatted the colors
302
303=== modified file 'usr/lib/byobu/date'
304--- usr/lib/byobu/date 2011-02-22 13:48:25 +0000
305+++ usr/lib/byobu/date 2011-05-18 18:29:02 +0000
306@@ -25,8 +25,10 @@
307 date +%Y-%m-%d
308 ;;
309 *)
310- msg="$(echo SGFwcHkgQmlydGhkYXkgU2NyZWVuIC0tIGh0dHA6Ly9iaXQubHkvc2NyZWVuLWJkYXkK | base64 -di)"
311- [ "$(date +%d)" = "20" ] && [ "$(date +%m)" = "03" ] && screen -X -S "byobu" at "*" echo "[$msg]"
312+ bd=$(date "+%m%d")
313+ [ "$bd" = "0320" ] &&
314+ msg="$(echo SGFwcHkgQmlydGhkYXkgU2NyZWVuIC0tIGh0dHA6Ly9iaXQubHkvc2NyZWVuLWJkYXkK | base64 -di)" &&
315+ screen -X -S "byobu" at "*" echo "[$msg]"
316 printf "\005Y-\005m-\005d "
317 ;;
318 esac
319
320=== modified file 'usr/lib/byobu/disk'
321--- usr/lib/byobu/disk 2010-04-26 23:28:24 +0000
322+++ usr/lib/byobu/disk 2011-05-18 18:29:02 +0000
323@@ -28,9 +28,26 @@
324 # Default to /, but let users override
325 [ -z "$MONITORED_DISK" ] && MP="/" || MP="$MONITORED_DISK"
326 case $MP in
327- /dev/*) MP=$(grep "$MP" /proc/mounts | awk '{print $2}') ;;
328+ /dev/*) MP=$(awk '$1 == m { print $2; exit(0); }' "m=$MP" /proc/mounts);;
329 esac
330
331-disk=$(df -h -P "$MP" 2>/dev/null || df -h "$MP")
332-disk=$(echo "$disk" | tail -n 1 | awk '{print $2 " " $5}' | sed "s/\([^0-9\. ]\)/ \1/g" | awk '{printf "%d%sB,%d%%", $1, $2, $3}')
333-printf "$(color M W)%s$(color -) " "$disk" | sed "s/\([0-9]\+\)/$(color -)$(color b M W)\1$(color -)$(color M W)/g"
334+get_size_pct() {
335+ # this could be done faster with 'stat --file-system --format'
336+ # but then we'd have to do blocks -> human units ourselves
337+ local out="" MP=$1 size="" pct="" unit=""
338+ out=$({ df -h -P "$MP" 2>/dev/null || df -h "$MP"; } |
339+ awk 'END { printf("%s %s", $2, $5); }')
340+ set -- ${out}
341+ size=${1}; pct=${2};
342+
343+ unit=${size#${size%?}} # get the unit (last char)
344+ size=${size%?}; # take the unit off
345+ pct=${pct%?}; # take off the '%'
346+
347+ _UNIT=${unit}; _SIZE=${size}; _PCT=${pct};
348+}
349+
350+get_size_pct "${MP}"
351+
352+color b M W; echo -n "$_SIZE"; color -; color M W; echo -n "${_UNIT}B,"; color -;
353+color b M W; echo -n "$_PCT"; color -; color M W; echo -n "%" ; color -;
354
355=== modified file 'usr/lib/byobu/disk_io'
356--- usr/lib/byobu/disk_io 2011-05-13 14:26:22 +0000
357+++ usr/lib/byobu/disk_io 2011-05-18 18:29:02 +0000
358@@ -20,20 +20,26 @@
359 PKG="byobu"
360 DATA="$HOME/.$PKG"
361 color 2>/dev/null || color() { true; }
362+getdisk() {
363+ local t=""
364+ if [ -L "${1}" ]; then
365+ command -v greadlink >/dev/null && READLINK=greadlink || READLINK=readlink
366+ t=$($READLINK -f "$1")
367+ else
368+ t="$1"
369+ fi
370+ t="${t##*/}";
371+ rtrim "$t" "0-9"
372+}
373+
374 [ "$UTF8" = "1" ] && ICON_RD="◀" || ICON_RD="<"
375 [ "$UTF8" = "1" ] && ICON_WR="▶" || ICON_WR=">"
376
377 # Default to disk providing /, but let users override with MONITORED_DISK
378 [ -z "$MONITORED_DISK" ] && MP="/" || MP="$MONITORED_DISK"
379-case $MP in
380- /dev/*) disk="$MP" ;;
381- *) disk=$(grep -m 1 " $MP " /etc/mtab | sed -e "s: .*$::") ;;
382-esac
383-which greadlink 2>/dev/null && READLINK="greadlink" || READLINK="readlink"
384-disk=$($READLINK -f "$disk" | sed -e "s: .*$::" -e "s:^.*/::" -e "s:\([hsv]d[a-z]\)[0-9]*$:\1:")
385
386 if [ "$1" = "--detail" ]; then
387- if which iostat >/dev/null; then
388+ if command -v >/dev/null; then
389 iostat -d -m -h
390 else
391 echo "Please install iostat if you want detailed information on your disk throughput"
392@@ -41,6 +47,13 @@
393 exit 0
394 fi
395
396+case "$MP" in
397+ /dev/*) part="${MP}";;
398+ *) part=$(awk '$2 == mp { print $1 ; exit(0); }' "mp=$MP" /etc/mtab);;
399+esac
400+getdisk "$part"
401+disk=${_RET}
402+
403 [ -d "/var/run/screen/S-$USER" ] && DIR="/var/run/screen/S-$USER" || DIR="$DATA"
404 t2=`date +%s`
405 for i in "read" "write"; do
406@@ -50,20 +63,21 @@
407 if [ $t2 -le $t1 ]; then
408 rate=0
409 else
410- x1=`cat "$cache"` 2>/dev/null || tx1=0
411+ [ -r "$cache" ] && read x1 < "$cache" || x1=0
412+ read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 other < "/sys/block/$disk/stat"
413 if [ "$i" = "read" ]; then
414 symbol="$ICON_RD"
415- x2=`awk '{print $3}' /sys/block/$disk/stat`
416+ x2="$a3"
417 else
418 symbol="$ICON_WR"
419- x2=`awk '{print $7}' /sys/block/$disk/stat`
420+ x2="$a7"
421 fi
422 echo "$x2" > "$cache"
423- rate=`echo "$t1" "$t2" "$x1" "$x2" | awk '{printf "%.0f", ($4 - $3) / ($2 - $1) * 512 / 1024 }'`
424+ rate=$((($x2-$x1) / ($t2 - $t1) * 512 / 1024))
425 if [ "$rate" -lt 0 ]; then
426 rate=0
427 elif [ "$rate" -gt 1024 ]; then
428- rate=`echo "$rate" | awk '{printf "%.1f", $1/1024}'`
429+ fpdiv "$rate" 1024 1
430 unit="MB/s"
431 fi
432 fi
433
434=== modified file 'usr/lib/byobu/fan_speed'
435--- usr/lib/byobu/fan_speed 2011-05-13 14:26:22 +0000
436+++ usr/lib/byobu/fan_speed 2011-05-18 18:29:02 +0000
437@@ -28,25 +28,35 @@
438
439 # Let's check a few different probes for fan speed
440
441-# This seems to cover most of them:
442-for i in $(find $DIR/*/*/ -type f -name "fan1_input"); do
443- speed=$(cat "$i")
444- if [ "$speed" -gt 0 ]; then
445- color bold1; printf "%s" "$speed"; color -; color none; printf "rpm"; color --
446- exit 0
447- fi
448-done
449-
450-# But others (e.g. Dell Inspirons) seem to be here:
451-if [ -r /proc/i8k ]; then
452- for speed in $(awk '{ print $7, $8 }' /proc/i8k); do
453+fan_speed_info() {
454+ local i="" speed=0
455+ # This seems to cover most of them:
456+ for i in /sys/class/hwmon/*/*/fan1_input; do
457+ [ -f "$i" ] || continue
458+ read speed < "$i"
459 if [ "$speed" -gt 0 ]; then
460- # I8K_FAN_MULT defaults to 30 (buggy BIOS workaround?),
461- # use `modprobe i8k fan_mult=1` to disable if unneeded,
462- # resulting in nonsensical speeds
463- [ "$speed" -gt 10000 ] && speed=$((${speed} / 30))
464 color bold1; printf "%s" "$speed"; color -; color none; printf "rpm"; color --
465- exit 0
466+ return 0
467 fi
468 done
469-fi
470+
471+ # But others (e.g. Dell Inspirons) seem to be here:
472+ if [ -r /proc/i8k ]; then
473+ local line=""
474+ read line < /proc/i8k
475+ set -- $line
476+ for speed in $7 $8; do
477+ if [ "$speed" -gt 0 ]; then
478+ # I8K_FAN_MULT defaults to 30 (buggy BIOS workaround?),
479+ # use `modprobe i8k fan_mult=1` to disable if unneeded,
480+ # resulting in nonsensical speeds
481+ [ "$speed" -gt 10000 ] && speed=$((${speed} / 30))
482+ color bold1; printf "%s" "$speed"; color -; color none; printf "rpm"; color --
483+ return 0
484+ fi
485+ done
486+ fi
487+}
488+
489+fan_speed_info "$@"
490+
491
492=== modified file 'usr/lib/byobu/ip_address'
493--- usr/lib/byobu/ip_address 2011-05-13 14:26:22 +0000
494+++ usr/lib/byobu/ip_address 2011-05-18 18:29:02 +0000
495@@ -35,8 +35,10 @@
496 interface="$MONITORED_NETWORK"
497 else
498 case "$IPV6" in
499- 1|true|yes) interface=$(grep -v "\Wlo$" /proc/net/ipv6_route | tail -n1 | awk '{print $10}') ;;
500- *) interface=$(tail -n1 /proc/net/route | awk '{print $1}') ;;
501+ 1|true|yes)
502+ interface=$(awk '$10 != "lo" { iface=$10 ; }; END { print iface; }' \
503+ /proc/net/ipv6_route);;
504+ *) interface=$(awk 'END {print $1}' /proc/net/route);;
505 esac
506 fi
507
508
509=== modified file 'usr/lib/byobu/load_average'
510--- usr/lib/byobu/load_average 2011-05-13 14:26:22 +0000
511+++ usr/lib/byobu/load_average 2011-05-18 18:29:02 +0000
512@@ -24,5 +24,5 @@
513 cat /proc/loadavg
514 exit 0
515 fi
516-
517-color Y k; printf "%s" "$(awk '{print $1}' /proc/loadavg)"; color --
518+read one five fifteen other < /proc/loadavg
519+color Y k; printf "$one"; color --
520
521=== modified file 'usr/lib/byobu/mem_available'
522--- usr/lib/byobu/mem_available 2011-05-13 14:26:22 +0000
523+++ usr/lib/byobu/mem_available 2011-05-18 18:29:02 +0000
524@@ -26,19 +26,26 @@
525 exit 0
526 fi
527
528-. "$DATA/status"
529-[ "$mem_used" = "1" ] && comma="," || whitespace=" "
530-
531-mem=`head -n1 /proc/meminfo | awk '{print $2}'`
532-if [ $mem -ge 1048576 ]; then
533- mem=$(echo "$mem" | awk '{ printf "%.1f", $1 / 1048576 }')
534- unit="GB"
535-elif [ $mem -ge 1024 ]; then
536- mem=$(echo "$mem" | awk '{ printf "%.0f", $1 / 1024 }')
537- unit="MB"
538-else
539- mem="$mem"
540- unit="KB"
541-fi
542-
543-color b g W; printf "%s" "$mem"; color -; color g W; printf "%s%s" "$unit" "$comma"; color -; printf "%s" "$whitespace"
544+mem_available_info() {
545+ local mem_used comma whitespace unit mem name
546+ . "$DATA/status"
547+ [ "$mem_used" = "1" ] && comma="," || whitespace=" "
548+
549+ read name mem unit < /proc/meminfo
550+ if [ $mem -ge 1048576 ]; then
551+ fpdiv "$mem" 1048567 1
552+ mem=${_RET}
553+ unit="GB"
554+ elif [ $mem -ge 1024 ]; then
555+ mem=$(echo "$mem" | awk '{ printf "%.0f", $1 / 1024 }')
556+ fpdiv "$mem" 1024 1
557+ mem=${_RET}
558+ unit="MB"
559+ else
560+ mem="$mem"
561+ unit="KB"
562+ fi
563+ color b g W; printf "%s" "$mem"; color -; color g W; printf "%s%s" "$unit" "$comma"; color -; printf "%s" "$whitespace"
564+}
565+
566+mem_available_info "$@"
567
568=== modified file 'usr/lib/byobu/mem_used'
569--- usr/lib/byobu/mem_used 2011-05-13 14:26:22 +0000
570+++ usr/lib/byobu/mem_used 2011-05-18 18:29:02 +0000
571@@ -25,5 +25,41 @@
572 exit 0
573 fi
574
575-f=$(free | awk '/buffers\/cache:/ {printf "%.0f", 100*$3/($3 + $4)}')
576+meminfo_used() {
577+ # originally, this script did:
578+ # f=$(free | awk '/buffers\/cache:/ {printf "%.0f", 100*$3/($3 + $4)}')
579+ # this method is more dependent on /proc/meminfo, but uses the same formula
580+ # for deriving the output of 'free' that is used in procps 'free.c'
581+
582+ # kb_main_free, kb_main_total, kb_main_buffers, kb_main_cached
583+ local free="" total="" buffers="" cached=""
584+ local kb_main_used=0 buffers_plus_cached=0 fo_buffers=0 fo_cached=0
585+ while read tok val unit; do
586+ case "$tok" in
587+ MemTotal:) total=${val};;
588+ MemFree:) free=${val};;
589+ Buffers:) buffers=${val};;
590+ Cached:) cached=${val};;
591+ esac
592+ [ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break;
593+ done < /proc/meminfo
594+
595+ kb_main_used=$(($total-$free))
596+ buffers_plus_cached=$(($buffers+$cached))
597+
598+ # "free output" buffers and cache (output from 'free')
599+ fo_buffers=$(($kb_main_used - $buffers_plus_cached))
600+ fo_cached=$(($kb_main_free + $buffers_plus_cached))
601+
602+ #fpdiv $((100*${fo_buffers})) "${total}" 0; _RET=${_RET%.}; return
603+ _RET=$(((100*${fo_buffers}) / ${total}))
604+}
605+
606+if [ -r /proc/meminfo ]; then
607+ meminfo_used
608+ f=${_RET}
609+else
610+ f=$(free | awk '/buffers\/cache:/ {printf "%.0f", 100*$3/($3 + $4)}')
611+fi
612+
613 color b g W; printf "%s" "$f"; color -; color g W; printf "%%"; color --
614
615=== modified file 'usr/lib/byobu/network'
616--- usr/lib/byobu/network 2011-05-13 14:26:22 +0000
617+++ usr/lib/byobu/network 2011-05-18 18:29:02 +0000
618@@ -27,7 +27,8 @@
619 if [ -n "$MONITORED_NETWORK" ]; then
620 interface="$MONITORED_NETWORK"
621 else
622- interface=`tail -n1 /proc/net/route | awk '{print $1}'`
623+ # get the last interface listed in /proc/net/route
624+ while read cn other; do interface=$cn; done < /proc/net/route
625 fi
626
627 if [ "$1" = "--detail" ]; then
628@@ -48,24 +49,27 @@
629 if [ $t2 -le $t1 ]; then
630 rate=0
631 else
632- x1=`cat "$cache"` 2>/dev/null || tx1=0
633- if [ "$i" = "up" ]; then
634- x2=`grep -m1 "\b$interface:" /proc/net/dev | sed "s/^.*://" | awk '{print $9}'`
635- else
636- x2=`grep -m1 "\b$interface:" /proc/net/dev | sed "s/^.*://" | awk '{print $1}'`
637- fi
638+ [ -r "$cache" ] && read x1 < "$cache" || tx1=0
639+ while read iface rbytes rpackets rerrs rdrop rfifo rframe rcompressed rmulticast tbytes tpackets terrs tdrop tfifo tcolls tcarrier tcompressed; do
640+ if [ "$iface" = "${interface}:" ]; then
641+ [ "$i" = "up" ] && x2=${tbytes} || x2=${rbytes}
642+ break;
643+ fi
644+ done < /proc/net/dev
645 echo "$x2" > "$cache"
646- rate=`echo "$t1" "$t2" "$x1" "$x2" | awk '{printf "%.0f", ($4 - $3) / ($2 - $1) / 1024 }'`
647+ rate=$((($x2 - $x1) / ($t2 - $t1) / 1024))
648 if [ "$rate" -lt 0 ]; then
649 rate=0
650 fi
651 case "$NETWORK_UNITS" in
652 bytes)
653 if [ "$rate" -gt 1048576 ]; then
654- rate=`echo "$rate" | awk '{printf "%.1f", $1/1048576}'`
655+ fpdiv "$rate" 1048576 1
656+ rate=${_RET}
657 unit="GB/s"
658 elif [ "$rate" -gt 1024 ]; then
659- rate=`echo "$rate" | awk '{printf "%.1f", $1/1024}'`
660+ fpdiv "$rate" 1024 1
661+ rate=${_RET}
662 unit="MB/s"
663 else
664 unit="kB/s"
665@@ -73,13 +77,15 @@
666 ;;
667 *)
668 # Default to bps
669- rate=`echo "$rate" | awk '{printf "%.0f", $1*8}'`
670+ rate=$(($rate*8))
671 # Why 1000 and not 1024? http://en.wikipedia.org/wiki/Data_rate_units
672 if [ "$rate" -gt 1000000 ]; then
673- rate=`echo "$rate" | awk '{printf "%.1f", $1/1000000}'`
674+ fpdiv "$rate" 1000000 1
675+ rate=${_RET}
676 unit="Gbps"
677 elif [ "$rate" -gt 1000 ]; then
678- rate=`echo "$rate" | awk '{printf "%.1f", $1/1000}'`
679+ fpdiv "$rate" 1000 1
680+ rate=${_RET}
681 unit="Mbps"
682 fi
683 ;;
684
685=== modified file 'usr/lib/byobu/raid'
686--- usr/lib/byobu/raid 2011-05-13 14:26:22 +0000
687+++ usr/lib/byobu/raid 2011-05-18 18:29:02 +0000
688@@ -29,16 +29,18 @@
689 ;;
690 esac
691
692-if grep -qs " blocks .*\[.*_.*\]$" /proc/mdstat; then
693+pct="%"
694+while read line; do
695 # Errors in your raid
696- msg="RAID"
697-fi
698-
699-if grep -qs \% /proc/mdstat; then
700- p=$(grep -m1 \% /proc/mdstat | sed -e "s/\%.*/%/" -e "s/.* //")
701- [ -z "$msg" ] && msg="RAID"
702- msg="$msg,$p"
703-fi
704+ case "$line" in
705+ *\ blocks\ *\[*_*\]$)
706+ [ -z "${msg}" ] && msg="RAID";;
707+ *%*)
708+ p="${line%%${pct}*}${pct}"; p=${p##* };
709+ [ -z "$msg" ] && msg="RAID"
710+ msg="$msg,$p";;
711+ esac
712+done < /proc/mdstat
713
714 if [ -n "$msg" ]; then
715 color B w r; printf "%s" "$msg"; color --
716
717=== modified file 'usr/lib/byobu/release'
718--- usr/lib/byobu/release 2011-05-13 14:26:22 +0000
719+++ usr/lib/byobu/release 2011-05-18 18:29:02 +0000
720@@ -25,45 +25,54 @@
721 exit 0
722 fi
723
724-if [ -n "$DISTRO" ]; then
725- # user defined
726- true
727-elif [ -r "/etc/issue" ]; then
728- # lsb_release is *really* slow; try to use /etc/issue first
729- issue=$(grep -m1 "^[A-Za-z]" /etc/issue)
730- case "$issue" in
731- Ubuntu*)
732- DISTRO=$(head -n1 /etc/issue | awk '{print $1 " " $2}')
733- ;;
734- Debian*)
735- DISTRO="Debian $(cat /etc/debian_version)"
736- ;;
737- *)
738- DISTRO=$(echo "$issue" | sed "s/ [^0-9]* / /" | awk '{print $1 " " $2}')
739- ;;
740- esac
741-elif which lsb_release >/dev/null 2>&1; then
742- if [ "$1" = "--detail" ]; then
743- lsb_release -a 2>/dev/null
744- exit 0
745+release_info() {
746+ local DISTRO="${DISTRO}" issue ver r i
747+ if [ -n "$DISTRO" ]; then
748+ # user defined
749+ true
750+ elif [ -r "/etc/issue" ]; then
751+ # lsb_release is *really* slow; try to use /etc/issue first
752+ read issue < /etc/issue
753+ case "$issue" in
754+ Ubuntu*)
755+ set -- $issue;
756+ DISTRO="$1 $2";
757+ ;;
758+ Debian*)
759+ read ver < /etc/debian_version
760+ DISTRO="Debian $ver"
761+ ;;
762+ *)
763+ # assume first 2 fields are what we want
764+ set -- $issue;
765+ DISTRO="$1 $2";
766+ ;;
767+ esac
768+ elif command -v lsb_release >/dev/null 2>&1; then
769+ if [ "$1" = "--detail" ]; then
770+ lsb_release -a 2>/dev/null
771+ exit 0
772+ fi
773+ # If lsb_release is available, use it
774+ r=$(lsb_release -s -d)
775+ case "$r" in
776+ Ubuntu*.*.*)
777+ # Use the -d if an Ubuntu LTS
778+ DISTRO="$r"
779+ ;;
780+ *)
781+ # But for other distros the description
782+ # is too long, so build from -i and -r
783+ i=$(lsb_release -s -i)
784+ r=$(lsb_release -s -r)
785+ DISTRO="$i $r"
786+ ;;
787+ esac
788+ else
789+ DISTRO="Byobu"
790 fi
791- # If lsb_release is available, use it
792- r=$(lsb_release -s -d)
793- case "$r" in
794- Ubuntu*.*.*)
795- # Use the -d if an Ubuntu LTS
796- DISTRO="$r"
797- ;;
798- *)
799- # But for other distros the description
800- # is too long, so build from -i and -r
801- i=$(lsb_release -s -i)
802- r=$(lsb_release -s -r)
803- DISTRO="$i $r"
804- ;;
805- esac
806-else
807- DISTRO="Byobu"
808-fi
809-
810-color bold2; printf "%s" "$DISTRO"; color --
811+
812+ color bold2; printf "%s" "$DISTRO"; color --
813+}
814+
815+release_info "$@"
816
817=== modified file 'usr/lib/byobu/swap'
818--- usr/lib/byobu/swap 2011-05-13 14:26:22 +0000
819+++ usr/lib/byobu/swap 2011-05-18 18:29:02 +0000
820@@ -25,19 +25,40 @@
821 exit 0
822 fi
823
824-f=$(free | awk '/Swap:/ {printf "%.0f", 100*$3/($3 + $4)}' 2>/dev/null || echo 0)
825-mem=$(free | awk '/Swap:/ {print $2}')
826-if [ $mem -ge 1048576 ]; then
827- mem=$(echo "$mem" | awk '{ printf "%.1f", $1 / 1048576 }')
828- unit="GB"
829-elif [ $mem -ge 1024 ]; then
830- mem=$(echo "$mem" | awk '{ printf "%.0f", $1 / 1024 }')
831- unit="MB"
832-else
833- mem="$mem"
834- unit="KB"
835-fi
836-
837-[ "$f" = "0" ] && exit 0
838-
839-color b G W; printf "s%s" "$mem"; color -; color G W; printf "%s," "$unit"; color -; color b G W; printf "%s" "$f"; color -; color G W; printf "%%"; color --
840+swap_info() {
841+ local stotal="" sfree="" name val unit mem f;
842+ while read name val unit; do
843+ if [ "$name" = "SwapTotal:" ]; then
844+ stotal="$val"
845+ elif [ "$name" = "SwapFree:" ]; then
846+ sfree="$val"
847+ else
848+ continue
849+ fi
850+ [ -n "$stotal" -a -n "$sfree" ] && break;
851+ done < /proc/meminfo
852+
853+ [ "${stotal:-0}" = "0" ] && return 0
854+
855+ mem=${stotal}
856+ f=$(((100*($stotal-$sfree))/$stotal))
857+ [ "$f" = "0" ] && return 0
858+ if [ $mem -ge 1048576 ]; then
859+ fpdiv "${mem}" 1048576 1
860+ mem=${_RET}
861+ unit="GB"
862+ elif [ $mem -ge 1024 ]; then
863+ fpdiv "${mem}" 1024 0
864+ mem=${_RET%.}
865+ unit="MB"
866+ else
867+ mem="$mem"
868+ unit="KB"
869+ fi
870+
871+ color b G W; printf "s%s" "$mem"; color -; color G W; printf "%s," "$unit"; color -;
872+ color b G W; printf "%s" "$f"; color -; color G W; printf "%%"; color --
873+ return
874+}
875+
876+swap_info "$@"
877
878=== modified file 'usr/lib/byobu/updates_available'
879--- usr/lib/byobu/updates_available 2011-05-13 14:26:22 +0000
880+++ usr/lib/byobu/updates_available 2011-05-18 18:29:02 +0000
881@@ -22,12 +22,12 @@
882 color 2>/dev/null || color() { true; }
883
884 if [ "$1" = "--detail" -o "$1" = "--short" ]; then
885- if which apt-get >/dev/null; then
886+ if command -v apt-get >/dev/null; then
887 detail=`apt-get -s -o Debug::NoLocking=true upgrade`
888 if [ "$1" = "--detail" ]; then
889 printf "$detail"
890 else
891- short=`printf "$detail" | grep -c ^Inst`
892+ short=`printf "%s" "$detail" | grep -c ^Inst`
893 printf "$short"
894 fi
895 fi
896@@ -61,18 +61,18 @@
897 # and let the next cache check pick up the results.
898 if [ -x /usr/lib/update-notifier/apt-check ]; then
899 # If apt-check binary exists, use it
900- /usr/lib/update-notifier/apt-check 2>&1 | tail -n 1 | sed "s/;/ /" > $mycache &
901- elif which apt-get >/dev/null; then
902+ /usr/lib/update-notifier/apt-check 2>&1 | awk '-F;' 'END { print $1, $2 }' > "$mycache" &
903+ elif command -v apt-get >/dev/null; then
904 # If apt-get exists, use it
905 apt-get -s -o Debug::NoLocking=true upgrade | grep -c ^Inst > $mycache &
906- elif which zypper >/dev/null; then
907+ elif command -v zypper >/dev/null; then
908 # If zypper exists, use it
909 zypper --no-refresh lu --best-effort | grep -c 'v |' > $mycache &
910- elif which yum >/dev/null; then
911+ elif command -v yum >/dev/null; then
912 # If yum exists, use it
913 # TODO: We need a better way of counting updates available from a RH expert
914 yum list updates -q | grep -vc "Updated Packages" > $mycache &
915- elif which pacman >/dev/null; then
916+ elif command -v pacman >/dev/null; then
917 # If pacman (Archlinux) exists, use it
918 LC_ALL=C pacman -Sup | grep -vc "^\(::\| \)" > $mycache &
919 fi
920@@ -84,11 +84,11 @@
921 mycache=$1
922 # The cache doesn't exist: create it
923 [ ! -e "$mycache" ] && return 0
924- if which apt-get >/dev/null; then
925+ if command -v apt-get >/dev/null; then
926 # Debian/ubuntu
927 [ "/var/lib/apt" -nt "$mycache" ] || [ "/var/lib/apt/lists" -nt "$mycache" ]
928 return $?
929- elif which pacman >/dev/null; then
930+ elif command -v pacman >/dev/null; then
931 # Archlinux
932 for db in /var/lib/pacman/sync/*.db; do
933 [ "$db" -nt "$mycache" ] && return 0
934@@ -102,7 +102,7 @@
935 mycache="$DIR/$PKG.updates-available"
936
937 # If mycache is present, use it
938-[ -r $mycache ] && print_updates `grep "^[0-9]" $mycache | sed "s/ .*$//"`
939+[ -r $mycache ] && print_updates `sed -n '/[^0-9]/s/ .*$//p' $mycache`
940
941 # If we really need to do so (mycache doesn't exist, or the package database has changed),
942 # background an update now
943
944=== modified file 'usr/lib/byobu/uptime'
945--- usr/lib/byobu/uptime 2011-05-13 14:26:22 +0000
946+++ usr/lib/byobu/uptime 2011-05-18 18:29:02 +0000
947@@ -28,15 +28,17 @@
948 exit 0
949 fi
950
951-u=$(sed "s/\..*$//" /proc/uptime)
952+read u idle < /proc/uptime
953+u=${u%.*}
954 color w b
955 if [ "$u" -gt 86400 ]; then
956- echo "$u" | awk '{printf "%dd%dh", $1 / 86400, ($1 % 86400)/3600 }'
957+ str="$(($u / 86400))d%$((($u % 86400) / 3600))h"
958 elif [ "$u" -gt 3600 ]; then
959- echo "$u" | awk '{printf "%dh%dm", $1 / 3600, ($1 % 3600 )/60}'
960+ str="$(($u / 3600))h$((($u % 3600) / 60))m"
961 elif [ "$u" -gt 60 ]; then
962- echo "$u" | awk '{printf "%dm", $1 / 60 }'
963+ str="$(($u / 60))m"
964 else
965- printf "%ds" "$u"
966+ str="${u}s"
967 fi
968+printf "%s" "${str}"
969 color --
970
971=== modified file 'usr/lib/byobu/wifi_quality'
972--- usr/lib/byobu/wifi_quality 2011-05-13 14:26:22 +0000
973+++ usr/lib/byobu/wifi_quality 2011-05-18 18:29:02 +0000
974@@ -26,14 +26,22 @@
975 exit 0
976 fi
977
978-iwconfig=`/sbin/iwconfig $MONITORED_NETWORK 2>/dev/null`
979-bitrate=`echo "$iwconfig" | grep "Bit Rate." | sed -e "s/^.*Bit Rate.//" -e "s/ .*$//g"`
980+# iwconfig is expected to output lines like:
981+# Bit Rate=54 Mb/s Tx-Power=15 dBm
982+# Link Quality=60/70 Signal level=-50 dBm
983+# the awk below tokenizes the output and prints shell evalable results
984+out=`iwconfig $MONITORED_NETWORK 2>/dev/null |
985+ awk '$0 ~ /[ ]*Link Quality./ {
986+ sub(/.*=/,"",$2); split($2,a,"/");
987+ printf "quality=%.0f\n", 100*a[1]/a[2] };
988+ $0 ~ /[ ]*Bit Rate/ { sub(/.*=/,"",$2); printf("bitrate=%s\n", $2); }
989+ '`
990+eval "$out"
991+
992 [ -z "$bitrate" ] && bitrate="0"
993-quality=`echo "$iwconfig" | grep "Link Quality." | sed -e "s/^.*Link Quality.//" -e "s/ .*$//g"`
994+
995 if [ -z "$quality" ] || [ "$quality" = "0" ]; then
996 quality="0"
997-else
998- quality=`echo "$quality" | awk -F/ '{printf "%.0f", 100*$1/$2}'`
999 fi
1000 [ "$quality" = "0" ] && exit 0
1001

Subscribers

People subscribed via source and target branches