* usr/lib/byobu/cpu_freq, usr/lib/byobu/cpu_temp,

usr/lib/byobu/custom, usr/lib/byobu/date, usr/lib/byobu/disk_io,
  usr/lib/byobu/ec2_cost, usr/lib/byobu/logo, usr/lib/byobu/network,
  usr/lib/byobu/rcs_cost, usr/lib/byobu/time_binary:
  - use printf where possible, saves some forks
This commit is contained in:
Dustin Kirkland 2012-02-12 09:18:12 -06:00
commit 6cb9b6064b
11 changed files with 28 additions and 23 deletions

5
debian/changelog vendored
View file

@ -20,6 +20,11 @@ byobu (5.8) unreleased; urgency=low
- move wifi_quality to second right status - move wifi_quality to second right status
* usr/bin/byobu-status, usr/lib/byobu/include/constants: * usr/bin/byobu-status, usr/lib/byobu/include/constants:
- use printf instead of echo, saves a few forks - use printf instead of echo, saves a few forks
* usr/lib/byobu/cpu_freq, usr/lib/byobu/cpu_temp,
usr/lib/byobu/custom, usr/lib/byobu/date, usr/lib/byobu/disk_io,
usr/lib/byobu/ec2_cost, usr/lib/byobu/logo, usr/lib/byobu/network,
usr/lib/byobu/rcs_cost, usr/lib/byobu/time_binary:
- use printf where possible, saves some forks
-- Dustin Kirkland <kirkland@ubuntu.com> Mon, 30 Jan 2012 18:12:49 -0600 -- Dustin Kirkland <kirkland@ubuntu.com> Mon, 30 Jan 2012 18:12:49 -0600

View file

@ -36,7 +36,7 @@ __cpu_freq() {
# Must scale frequency by number of processors, if counting bogomips # Must scale frequency by number of processors, if counting bogomips
count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo) count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo)
freq=$(egrep -i -m 1 "^bogomips" /proc/cpuinfo | awk -F"[:.]" '{ print $2 }') freq=$(egrep -i -m 1 "^bogomips" /proc/cpuinfo | awk -F"[:.]" '{ print $2 }')
freq=$(echo "$freq" "$count" | awk '{printf "%01.1f\n", $1/$2/1000}') freq=$(printf "%s %s" "$freq" "$count" | awk '{printf "%01.1f\n", $1/$2/1000}')
fi fi
fi fi
color b c W; printf "%s" "$freq"; color -; color c W; printf "%s" "$ICON_GHz"; color -- color b c W; printf "%s" "$freq"; color -; color c W; printf "%s" "$ICON_GHz"; color --

View file

@ -23,7 +23,7 @@ __cpu_temp_detail() {
local i local i
for i in $MONITORED_TEMP /sys/class/hwmon/hwmon*/temp*_input /sys/class/hwmon/hwmon*/device/temp*_input /proc/acpi/ibm/thermal /proc/acpi/thermal_zone/*/temperature; do for i in $MONITORED_TEMP /sys/class/hwmon/hwmon*/temp*_input /sys/class/hwmon/hwmon*/device/temp*_input /proc/acpi/ibm/thermal /proc/acpi/thermal_zone/*/temperature; do
[ -r "$i" ] || continue [ -r "$i" ] || continue
echo "$i:" printf "%s\n" "$i:"
cat "$i"/* cat "$i"/*
done done
} }

View file

@ -38,7 +38,7 @@ __custom() {
local expiration=$(($lastrun+$freq)) local expiration=$(($lastrun+$freq))
if [ $now -ge $expiration ]; then if [ $now -ge $expiration ]; then
"$i" > "$cache.$script" 2>/dev/null "$i" > "$cache.$script" 2>/dev/null
echo "${now}" > "$cache.$script.last" printf "%s\n" "${now}" > "$cache.$script.last"
fi fi
readfile < "$cache.$script" readfile < "$cache.$script"
local str="${_RET}" local str="${_RET}"

View file

@ -30,7 +30,7 @@ __date() {
;; ;;
screen) screen)
bd=$(date "+%m%d") bd=$(date "+%m%d")
[ "$bd" = "0320" ] && msg="$(echo SGFwcHkgQmlydGhkYXkgU2NyZWVuIC0tIGh0dHA6Ly9iaXQubHkvc2NyZWVuLWJkYXkK | base64 -di)" && $BYOBU_BACKEND -X -S "byobu" at "*" echo "[$msg]" [ "$bd" = "0320" ] && msg="$(printf "%s" SGFwcHkgQmlydGhkYXkgU2NyZWVuIC0tIGh0dHA6Ly9iaXQubHkvc2NyZWVuLWJkYXkK | base64 -di)" && $BYOBU_BACKEND -X -S "byobu" at "*" echo "[$msg]"
color none; printf "\005Y-\005m-\005d"; color -- color none; printf "\005Y-\005m-\005d"; color --
;; ;;
esac esac

View file

@ -23,7 +23,7 @@ __disk_io_detail() {
if command -v iostat >/dev/null; then if command -v iostat >/dev/null; then
iostat -d -m -h iostat -d -m -h
else else
echo "Please install iostat if you want detailed information on your disk throughput" printf "%s\n" "Please install iostat if you want detailed information on your disk throughput"
fi fi
} }
@ -71,7 +71,7 @@ __disk_io() {
symbol="$ICON_WR" symbol="$ICON_WR"
x2="$a7" x2="$a7"
fi fi
echo "$x2" > "$cache" printf "%s" "$x2" > "$cache"
rate=$((($x2 - $x1) / ($t2 - $t1) * 512 / 1024)) rate=$((($x2 - $x1) / ($t2 - $t1) * 512 / 1024))
if [ $rate -lt $DISK_IO_THRESHOLD ]; then if [ $rate -lt $DISK_IO_THRESHOLD ]; then
# Below threshold, don't print # Below threshold, don't print

View file

@ -68,7 +68,7 @@ __ec2_cost() {
rate=$m1_large rate=$m1_large
else else
# Otherwise, scale based on number of cpu's (c* types) # Otherwise, scale based on number of cpu's (c* types)
rate=$(echo "$cpu" "$m1_small" | awk '{printf "%f", $1*$2}') rate=$(printf "%s %s" "$cpu" "$m1_small" | awk '{printf "%f", $1*$2}')
fi fi
fi fi
hours=$(((`date +%s` - `stat --printf %Y $file_to_stat`) / 60 / 60 + 1)) hours=$(((`date +%s` - `stat --printf %Y $file_to_stat`) / 60 / 60 + 1))
@ -95,12 +95,12 @@ __ec2_cost() {
break break
fi fi
done < /proc/net/dev done < /proc/net/dev
tx_gb=$(echo ${tx_gb} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') tx_gb=$(printf "%s" ${tx_gb} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
rx_gb=$(echo ${rx_gb} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') rx_gb=$(printf "%s" ${rx_gb} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
network_cost=`echo "$tx_gb" "$TX_RATE" "$rx_gb" "$RX_RATE" | awk '{printf "%f %f", $1*$2, $3*$4}' | awk '{printf "%f", $1 + $2}'` network_cost=`printf "%s %s %s %s" "$tx_gb" "$TX_RATE" "$rx_gb" "$RX_RATE" | awk '{printf "%f %f", $1*$2, $3*$4}' | awk '{printf "%f", $1 + $2}'`
# Calculate uptime cost # Calculate uptime cost
uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$rate" * $hours}"` uptime_cost=`printf "%s" "$hours" | awk "{printf \"%f\", "$rate" * $hours}"`
total_cost=`echo "$network_cost" "$uptime_cost" | awk '{printf "%.2f", $1 + $2}'` total_cost=`printf "%s %s" "$network_cost" "$uptime_cost" | awk '{printf "%.2f", $1 + $2}'`
if [ "$DETAIL" = "1" ]; then if [ "$DETAIL" = "1" ]; then
echo "================================================" echo "================================================"
echo "Estimated cost in Amazon's EC2 since last reboot" echo "Estimated cost in Amazon's EC2 since last reboot"
@ -108,7 +108,7 @@ __ec2_cost() {
echo " Network sent: $tx_gb GB @ \$$RX_RATE/GB" echo " Network sent: $tx_gb GB @ \$$RX_RATE/GB"
echo " Network recv: $rx_gb GB @ \$$TX_RATE/GB" echo " Network recv: $rx_gb GB @ \$$TX_RATE/GB"
echo " Network cost: \$$network_cost" echo " Network cost: \$$network_cost"
echo "------------------------------------------------" echo "------------------------------------------------"
echo " Uptime: $hours hr @ \$$rate/hr" echo " Uptime: $hours hr @ \$$rate/hr"
echo " Uptime cost: \$$uptime_cost" echo " Uptime cost: \$$uptime_cost"
echo "------------------------------------------------" echo "------------------------------------------------"

View file

@ -50,7 +50,7 @@ __logo() {
return return
fi fi
get_distro get_distro
local distro="$(echo "$_RET" | $BYOBU_SED 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')" local distro="$(printf "%s" "$_RET" | $BYOBU_SED 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')"
case "$distro" in case "$distro" in
*ubuntu*) *ubuntu*)
if $MARKUP; then if $MARKUP; then

View file

@ -54,7 +54,7 @@ __network() {
;; ;;
esac esac
done < /proc/net/dev done < /proc/net/dev
echo "$x2" > "$cache" printf "%s" "$x2" > "$cache"
rate=$((8*($x2 - $x1) / $t / 1024)) # in kbps rate=$((8*($x2 - $x1) / $t / 1024)) # in kbps
[ "$rate" -lt 0 ] && rate=0 [ "$rate" -lt 0 ] && rate=0
if [ $rate -gt $NETWORK_THRESHOLD ]; then if [ $rate -gt $NETWORK_THRESHOLD ]; then

View file

@ -50,7 +50,7 @@ __rcs_cost() {
for X in ${INCREMENTS}; do for X in ${INCREMENTS}; do
test "$((${X} * 1024 + 65536))" -ge ${memory} && break test "$((${X} * 1024 + 65536))" -ge ${memory} && break
done done
MEMORY_RATE=`echo "$X" | awk '{printf "%f", $1 / 256 * 15 / 1000}'` MEMORY_RATE=`printf "%s" "$X" | awk '{printf "%f", $1 / 256 * 15 / 1000}'`
# Data Transfer Cost Basis # Data Transfer Cost Basis
# Incoming $0.08/GB # Incoming $0.08/GB
@ -65,15 +65,15 @@ __rcs_cost() {
# Calculate bandwidth cost # Calculate bandwidth cost
tx_gb=${ifconfig_out#*RX bytes:} tx_gb=${ifconfig_out#*RX bytes:}
tx_gb=$(echo ${tx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') tx_gb=$(printf "%s" ${tx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
rx_gb=${ifconfig_out#*TX bytes:} rx_gb=${ifconfig_out#*TX bytes:}
rx_gb=$(echo ${rx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') rx_gb=$(printf "%s" ${rx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
network_cost=`echo "$tx_gb" "$TX_RATE" "$rx_gb" "$RX_RATE" | awk '{printf "%f %f", $1*$2, $3*$4}' | awk '{printf "%f", $1 + $2}'` network_cost=`printf "%s" "$tx_gb" "$TX_RATE" "$rx_gb" "$RX_RATE" | awk '{printf "%f %f", $1*$2, $3*$4}' | awk '{printf "%f", $1 + $2}'`
# Calculate uptime cost # Calculate uptime cost
hours=$(((`date +%s` - `stat --printf %Z /etc/hostname`) / 60 / 60 + 1)) hours=$(((`date +%s` - `stat --printf %Z /etc/hostname`) / 60 / 60 + 1))
uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$MEMORY_RATE" * $hours}"` uptime_cost=`printf "%s" "$hours" | awk "{printf \"%f\", "$MEMORY_RATE" * $hours}"`
total_cost=`echo "$network_cost" "$uptime_cost" | awk '{printf "%.2f", $1 + $2}'` total_cost=`printf "%s %s" "$network_cost" "$uptime_cost" | awk '{printf "%.2f", $1 + $2}'`
if [ "$DETAIL" = "1" ]; then if [ "$DETAIL" = "1" ]; then
echo "==========================================================" echo "=========================================================="

View file

@ -128,7 +128,7 @@ done
if [ -z "$clock_type" ] if [ -z "$clock_type" ]
then then
echo "ERROR: must specify clock type" printf "%s\n" "ERROR: must specify clock type"
exit 1 exit 1
fi fi
@ -169,5 +169,5 @@ else
display_time="${hh}${sep}${hm}${hs}${ending}" display_time="${hh}${sep}${hm}${hs}${ending}"
fi fi
echo -ne "$display_time" printf "%s" "$display_time"
exit 0 exit 0