-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FreeBSD support for common widgets #51
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your pull request. I would love to have a more sophisticated support of the FreeBSD operating system.
@@ -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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To some people regular expressions may be witchcraft. Maybe we can instead write this as:
sysctl -n vm.loadavg | read brace_left one five fifteen brace_right
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you do not perform error checking of any kind, these can be grouped into one sysctl
command:
sysctl -n hw.physmem hw.pagesize vm.stats.vm.v_inactive_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count | \
read mem_phys page_size mem_inactive mem_cache mem_free
The factor is applied subsequently:
mem_inactive=$(($mem_inactive*$page_size))
mem_cache=$(($mem_cache*$page_size))
mem_free=$(($mem_free*$page_size))
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently getconf _NPROCESSORS_ONLN
succeeds on a FreeBSD system, hence the sysctl
is never invoked (via ||
list-operator).
fpdiv $hz "1000000000" 1 | ||
freq="$_RET" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary duplication of code. The same can be achieved via:
elif hz=$(sysctl -n hw.cpufrequency 2>/dev/null || sysctl -n machdep.tsc_freq 2>/dev/null); then
Ideally insert a comment saying which OID is available on which system.
df -h -P | ||
if [ $(uname) = "FreeBSD" ]; then | ||
df -h | ||
else | ||
df -h -P | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Granted ‑P
has a different meaning in the FreeBSD version of df
, it does not matter since ‑h
renders the effects of ‑P
irrelevant. There is no column indicating the size in blocks.
df -Ph # order matters: with FreeBSD's version of df the -P option must be overridden by -h
Hi all! I'm actually keen to get this merged in. I don't have any Mac / FreeBSD systems, but if someone could update this branch with a clean, working set, I'll ensure that it doesn't regress anything on non-Mac/BSD systems and get it merged... |
No description provided.