commit: ac5f9575ad1fd7953d8c9c249ae1a0d0d7024e9b
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Tue Jul 9 11:01:28 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Jul 9 11:03:54 2024 +0000
URL:
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=ac5f9575
Have _update_time() measure in centiseconds
Doing so simplifies the case where /proc/uptime is read. Having one more
digit's worth of accuracy is no bad thing either.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
functions.sh | 53 ++++++++++++++++++++++-------------------------------
1 file changed, 22 insertions(+), 31 deletions(-)
diff --git a/functions.sh b/functions.sh
index ad509fa..7f4bc25 100644
--- a/functions.sh
+++ b/functions.sh
@@ -706,7 +706,7 @@ _select_by_mtime() {
}
#
-# Considers the first parameter as a number of deciseconds and determines
+# Considers the first parameter as a number of centiseconds and determines
# whether fewer have elapsed since the last occasion on which the function was
# called.
#
@@ -733,14 +733,14 @@ _update_columns()
_update_columns()
{
# Two optimisations are applied. Firstly, the rate at which
- # updates can be performed is throttled to intervals of 5
- # deciseconds. Secondly, if running on bash then the COLUMNS
- # variable may be gauged, albeit only in situations where doing
- # so can be expected to work reliably; it is an unreliable
- # method where operating from a subshell. Note that executing
- # true(1) is faster than executing stty(1) within a comsub.
+ # updates can be performed is throttled to intervals of half a
+ # second. Secondly, if running on bash then the COLUMNS variable
+ # may be gauged, albeit only in situations where doing so can be
+ # expected to work reliably; it is an unreliable method where
+ # operating from a subshell. Note that executing true(1) is
+ # faster than executing stty(1) within a comsub.
# shellcheck disable=3028
- if _should_throttle 5; then
+ if _should_throttle 50; then
test "${genfun_cols}"
return
elif [ "${genfun_bin_true}" ] && [ "$$" = "${BASHPID}" ]; then
@@ -761,11 +761,11 @@ _update_columns()
}
#
-# Determines either the number of deciseconds elapsed since the unix epoch or
-# the number of deciseconds that the operating system has been online,
depending
-# on the capabilities of the shell and/or platform. Upon success, the obtained
-# value shall be assigned to genfun_time. Otherwise, the return value shall be
-# greater than 0.
+# Determines either the number of centiseconds elapsed since the unix epoch or
+# the number of centiseconds that the operating system has been online,
+# depending on the capabilities of the shell and/or platform. Upon success, the
+# obtained value shall be assigned to genfun_time. Otherwise, the return value
+# shall be greater than 0.
#
_update_time()
{
@@ -776,34 +776,25 @@ _update_time()
# shellcheck disable=2034,3045
_update_time()
{
- local ds s timeval
+ local cs s timeval
timeval=${EPOCHREALTIME}
s=${timeval%.*}
- printf -v ds '%.1f' ".${timeval#*.}"
- if [ "${ds}" = "1.0" ]; then
- ds=10
+ printf -v cs '%.2f' ".${timeval#*.}"
+ if [ "${cs}" = "1.00" ]; then
+ cs=100
else
- ds=${ds#0.}
+ cs=${cs#0.} cs=${cs#0}
fi
- genfun_time=$(( s * 10 + ds ))
+ genfun_time=$(( s * 100 + cs ))
}
elif [ -f /proc/uptime ]; then
_update_time()
{
- local cs ds s timeval
+ local cs s
- IFS=' ' read -r timeval _ < /proc/uptime || return
- s=${timeval%.*}
- cs=${timeval#*.}
- case ${cs} in
- ?[0-4])
- ds=${cs%?}
- ;;
- ?[5-9])
- ds=$(( ${cs%?} + 1 ))
- esac
- genfun_time=$(( s * 10 + ds ))
+ IFS='. ' read -r s cs _ < /proc/uptime \
+ && genfun_time=$(( s * 100 + ${cs#0} ))
}
else
_update_time()