From 6acdb68e5939faf676655455e9081e62beb5b5e2 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Tue, 16 Jun 2009 16:35:56 -0500 Subject: [PATCH] * bin/network, profiles/common, profiles/profile.skel: merge network_down and network_up to a single status script; too much duplication of code, causes performance problems Signed-off-by: Dustin Kirkland --- bin/network_down | 54 ------------------------------------------ bin/network_up | 55 ------------------------------------------- debian/changelog | 5 +++- profiles/common | 4 ++-- profiles/profile.skel | 2 +- 5 files changed, 7 insertions(+), 113 deletions(-) delete mode 100755 bin/network_down delete mode 100755 bin/network_up diff --git a/bin/network_down b/bin/network_down deleted file mode 100755 index 09d3213f..00000000 --- a/bin/network_down +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh -e -# -# network_down: calculate the network receive rate -# Copyright (C) 2008 Canonical Ltd. -# -# Authors: Dustin Kirkland -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, version 3 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -PKG="byobu" - -cache="/var/run/screen/S-$USER/$PKG.network_down" -unit="kB/s" - -# Allow interface overrides in configuration directory -if [ -r "$HOME/.$PKG/network" ]; then - interface=`cat "$HOME/.$PKG/network"` -else - interface=`/sbin/route -n | tail -n 1 | sed "s/^.* //"` -fi - -if [ "$1" = "--detail" ]; then - /sbin/ifconfig "$interface" | sed 's/\s*$//' - exit 0 -fi - -t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0 -t2=`date +%s` - -if [ $t2 -le $t1 ]; then - rate=0 -else - x1=`cat "$cache"` 2>/dev/null || tx1=0 - x2=`/sbin/ifconfig "$interface" | grep "RX bytes" | sed "s/^.*RX bytes://" | sed "s/ .*$//"` - echo "$x2" > "$cache" - rate=`echo "$t1" "$t2" "$x1" "$x2" | awk '{printf "%.0f", ($4 - $3) / ($2 - $1) / 1024 }'` - if [ "$rate" -lt 0 ]; then - rate=0 - elif [ "$rate" -gt 1024 ]; then - rate=`echo "$rate" | awk '{printf "%.1f", $1/1024}'` - unit="MB/s" - fi -fi -printf "v\005{=b mw}$rate\005{-}\005{= mw}$unit\005{-} " diff --git a/bin/network_up b/bin/network_up deleted file mode 100755 index b5b23fb2..00000000 --- a/bin/network_up +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/sh -e -# -# network_up: calculate the network transmit rate -# Copyright (C) 2008 Canonical Ltd. -# -# Authors: Dustin Kirkland -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, version 3 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -PKG="byobu" - -cache="/var/run/screen/S-$USER/$PKG.network_up" -unit="kB/s" - -# Allow interface overrides in configuration directory -if [ -r "$HOME/.$PKG/network" ]; then - interface=`cat "$HOME/.$PKG/network"` -else - interface=`/sbin/route -n | tail -n 1 | sed "s/^.* //"` -fi - - -if [ "$1" = "--detail" ]; then - /sbin/ifconfig "$interface" | sed 's/\s*$//' - exit 0 -fi - -t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0 -t2=`date +%s` - -if [ $t2 -le $t1 ]; then - rate=0 -else - x1=`cat "$cache"` 2>/dev/null || tx1=0 - x2=`/sbin/ifconfig "$interface" | grep "TX bytes" | sed "s/^.*TX bytes://" | sed "s/ .*$//"` - echo "$x2" > "$cache" - rate=`echo "$t1" "$t2" "$x1" "$x2" | awk '{printf "%.0f", ($4 - $3) / ($2 - $1) / 1024 }'` - if [ "$rate" -lt 0 ]; then - rate=0 - elif [ "$rate" -gt 1024 ]; then - rate=`echo "$rate" | awk '{printf "%.1f", $1/1024}'` - unit="MB/s" - fi -fi -printf "^\005{=b mw}$rate\005{-}\005{= mw}$unit\005{-} " diff --git a/debian/changelog b/debian/changelog index 8a22e724..77688cbc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -14,8 +14,11 @@ byobu (2.12) unreleased; urgency=low * bin/wifi_quality: significant performance improvements, remove unneeded route call, cache iwconfig output so that it's only called once * bin/processes: improve performance by listing /proc (doubles the speed) + * bin/network, profiles/common, profiles/profile.skel: merge network_down + and network_up to a single status script; too much duplication of code, + causes performance problems - -- Dustin Kirkland Tue, 16 Jun 2009 16:10:36 -0500 + -- Dustin Kirkland Tue, 16 Jun 2009 16:35:01 -0500 byobu (2.11-0ubuntu1) karmic; urgency=low diff --git a/profiles/common b/profiles/common index 847a40c7..b78f7b12 100644 --- a/profiles/common +++ b/profiles/common @@ -44,8 +44,8 @@ backtick 113 30 30 byobu-status battery backtick 114 10 10 byobu-status users backtick 115 60 60 byobu-status uptime backtick 116 2 2 byobu-status processes -backtick 117 2 2 byobu-status network_up -backtick 118 2 2 byobu-status network_down +backtick 117 2 2 byobu-status network +backtick 118 86400 86400 true backtick 119 10 10 byobu-status wifi_quality backtick 120 86400 86400 byobu-status date backtick 121 86400 86400 byobu-status time diff --git a/profiles/profile.skel b/profiles/profile.skel index 98f45b79..8d419510 100644 --- a/profiles/profile.skel +++ b/profiles/profile.skel @@ -26,7 +26,7 @@ source /usr/share/byobu/profiles/common caption always "%{kW}%?%-Lw%?%{bw}%n*%f %t%?(%u)%?%{kW}%?%+Lw%? %= %{= Wk}%110`%109`%122`%111`" # Status string, last line -hardstatus string '%99`%{= Wk} %100`%112`%= %102`%101`%114`%115`%108`%125`%126`%113`%119`%117`%118`%116`%106`%104`%103`%105`%107`%123`%124`%120`%121`' +hardstatus string '%99`%{= Wk} %100`%112`%= %102`%101`%114`%115`%108`%125`%126`%113`%119`%117``%116`%106`%104`%103`%105`%107`%123`%124`%120`%121`' # NOTE: Older version of screen have an arbitrary limit of only being able # to change colors 16 times in this 'hardstatus string'.