mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-21 05:53:22 -07:00
Merge 05a8d33b01
into bfb7a763d0
This commit is contained in:
commit
f440021855
8 changed files with 64 additions and 22 deletions
|
@ -25,7 +25,9 @@ __cpu_count_detail() {
|
|||
|
||||
__cpu_count() {
|
||||
local c
|
||||
c=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo)
|
||||
c=$(getconf _NPROCESSORS_ONLN 2>/dev/null || \
|
||||
grep -ci "^processor" /proc/cpuinfo || \
|
||||
sysctl -n hw.ncpu)
|
||||
[ "$c" = "1" ] || printf "%sx" "$c"
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ __cpu_freq_detail() {
|
|||
|
||||
__cpu_freq() {
|
||||
local hz freq count
|
||||
|
||||
if [ -r "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" ]; then
|
||||
read hz < /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
|
||||
fpdiv $hz "1000000" 1 # 1Ghz
|
||||
|
@ -33,7 +34,6 @@ __cpu_freq() {
|
|||
if egrep -q -s -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo; then
|
||||
freq=$(egrep -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo | awk -F"[:.]" '{ printf "%01.1f", $2 / 1000 }')
|
||||
else
|
||||
# Must scale frequency by number of processors, if counting bogomips
|
||||
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=$(printf "%s %s" "$freq" "$count" | awk '{printf "%01.1f\n", $1/$2/1000}')
|
||||
|
@ -41,7 +41,11 @@ __cpu_freq() {
|
|||
elif hz=$(sysctl -n hw.cpufrequency 2>/dev/null); then
|
||||
fpdiv $hz "1000000000" 1 # 1Ghz
|
||||
freq="$_RET"
|
||||
elif hz=$(sysctl -n machdep.tsc_freq 2>/dev/null); then
|
||||
fpdiv $hz "1000000000" 1
|
||||
freq="$_RET"
|
||||
fi
|
||||
|
||||
[ -n "$freq" ] || return
|
||||
color b c W; printf "%s" "$freq"; color -; color c W; printf "%s" "$ICON_GHz"; color --
|
||||
}
|
||||
|
|
|
@ -20,7 +20,11 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
__disk_detail() {
|
||||
df -h -P
|
||||
if [ $(uname) = "FreeBSD" ]; then
|
||||
df -h
|
||||
else
|
||||
df -h -P
|
||||
fi
|
||||
}
|
||||
|
||||
__disk() {
|
||||
|
@ -32,7 +36,11 @@ __disk() {
|
|||
esac
|
||||
# this could be done faster with 'stat --file-system --format'
|
||||
# but then we'd have to do blocks -> human units ourselves
|
||||
out=$({ df -h -P "$MP" 2>/dev/null || df -h "$MP"; } | awk 'END { printf("%s %s", $2, $5); }')
|
||||
if [ $(uname) = "FreeBSD" ]; then
|
||||
out=$({ df -h "$MP" 2>/dev/null || df -h "$MP"; } | awk 'END { printf("%s %s", $2, $5); }')
|
||||
else
|
||||
out=$({ df -h -P "$MP" 2>/dev/null || df -h "$MP"; } | awk 'END { printf("%s %s", $2, $5); }')
|
||||
fi
|
||||
set -- ${out}
|
||||
size=${1}; pct=${2};
|
||||
unit=${size#${size%?}} # get the unit (last char)
|
||||
|
|
|
@ -26,6 +26,8 @@ __load_average_detail() {
|
|||
__load_average() {
|
||||
if [ -r "/proc/loadavg" ]; then
|
||||
read one five fifteen other < /proc/loadavg
|
||||
elif [ $(uname) = "FreeBSD" ]; then
|
||||
one=$(uptime | sed -En 's:.*averages\: ([[:digit:]]+\.[[:digit:]]+),.*:\1:p')
|
||||
else
|
||||
one=$(uptime | sed -e "s/.*://" | awk '{print $1}')
|
||||
fi
|
||||
|
|
|
@ -26,16 +26,35 @@ __memory_detail() {
|
|||
__memory() {
|
||||
local free="" total="" buffers="" cached=""
|
||||
local kb_main_used=0 buffers_plus_cached=0 fo_buffers=0 fo_cached=0
|
||||
if [ -r /proc/meminfo ]; then
|
||||
while read tok val unit; do
|
||||
case "$tok" in
|
||||
MemTotal:) total=${val};;
|
||||
MemFree:) free=${val};;
|
||||
Buffers:) buffers=${val};;
|
||||
Cached:) cached=${val};;
|
||||
esac
|
||||
[ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break;
|
||||
done < /proc/meminfo
|
||||
|
||||
if [ $(uname) = "Linux" ]; then
|
||||
if [ -r /proc/meminfo ]; then
|
||||
while read tok val unit; do
|
||||
case "$tok" in
|
||||
MemTotal:) total=${val};;
|
||||
MemFree:) free=${val};;
|
||||
Buffers:) buffers=${val};;
|
||||
Cached:) cached=${val};;
|
||||
esac
|
||||
[ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break;
|
||||
done < /proc/meminfo
|
||||
fi
|
||||
elif [ $(uname) = "FreeBSD" ]; then
|
||||
# FreeBSD support
|
||||
mem_phys=$(sysctl -n hw.physmem)
|
||||
page_size=$(sysctl -n hw.pagesize)
|
||||
mem_inactive=$(($(sysctl -n vm.stats.vm.v_inactive_count)*$page_size))
|
||||
mem_cache=$(($(sysctl -n vm.stats.vm.v_cache_count)*$page_size))
|
||||
mem_free=$(($(sysctl -n vm.stats.vm.v_free_count)*$page_size))
|
||||
|
||||
mem_avail=$(($mem_inactive+$mem_cache+$mem_free))
|
||||
mem_used=$(($mem_phys-$mem_avail))
|
||||
|
||||
total=$(($mem_phys/1024))
|
||||
free=$(($mem_avail/1024))
|
||||
|
||||
buffers=0
|
||||
cached=0
|
||||
elif eval $BYOBU_TEST vm_stat >/dev/null 2>&1; then
|
||||
# MacOS support
|
||||
# calculation borrowed from http://apple.stackexchange.com/a/48195/18857
|
||||
|
@ -44,16 +63,18 @@ __memory() {
|
|||
speculative_blocks=$(vm_stat | grep speculative | awk '{ print $3 }' | sed -e 's/\.//')
|
||||
free=$((($free_blocks+speculative_blocks)*4))
|
||||
inactive=$(($inactive_blocks*4))
|
||||
total=$((($free+$inactive)))
|
||||
total=$(($free+$inactive))
|
||||
buffers=0
|
||||
cached=0
|
||||
fi
|
||||
kb_main_used=$(($total-$free))
|
||||
buffers_plus_cached=$(($buffers+$cached))
|
||||
# "free output" buffers and cache (output from 'free')
|
||||
fo_buffers=$(($kb_main_used - $buffers_plus_cached))
|
||||
fpdiv $((100*${fo_buffers})) "${total}" 0;
|
||||
usage=${_RET}
|
||||
|
||||
kb_main_used=$(($total-$free))
|
||||
buffers_plus_cached=$(($buffers+$cached))
|
||||
# "free output" buffers and cache (output from 'free')
|
||||
fo_buffers=$(($kb_main_used - $buffers_plus_cached))
|
||||
fpdiv $((100*${fo_buffers})) "${total}" 0;
|
||||
usage=${_RET}
|
||||
|
||||
if [ $total -ge 1048576 ]; then
|
||||
fpdiv "$total" 1048567 1
|
||||
total=${_RET}
|
||||
|
|
|
@ -172,3 +172,5 @@ fi
|
|||
color k w
|
||||
printf "%s" "$display_time"
|
||||
color --
|
||||
|
||||
# vi: syntax=sh ts=4 noexpandtab
|
||||
|
|
|
@ -34,4 +34,4 @@ __trash() {
|
|||
printf "%s[%s]" "$ICON_TRASH" "$count"
|
||||
}
|
||||
|
||||
# vi: syntax=sh ts=4 noexpandtab
|
||||
# vi: syntax=sh ts=4 noexpandtab
|
|
@ -30,6 +30,9 @@ __uptime() {
|
|||
if [ -r /proc/uptime ]; then
|
||||
read u idle < /proc/uptime
|
||||
u=${u%.*}
|
||||
elif [ $(uname) = "FreeBSD" ]; then
|
||||
u=$(sysctl -n kern.boottime | sed -En 's:.*sec = ([[:digit:]]+),.*:\1:p')
|
||||
u=$(($(date +%s) - $u))
|
||||
elif [ -x /usr/sbin/sysctl ]; then
|
||||
# MacOS support
|
||||
u=$(/usr/sbin/sysctl -n kern.boottime | cut -f4 -d' ' | cut -d',' -f1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue