From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id D571A159C9B for ; Fri, 2 Aug 2024 23:14:15 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7B71EE2A4B; Fri, 2 Aug 2024 23:14:14 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 5D54FE2A43 for ; Fri, 2 Aug 2024 23:14:14 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 51B8734300B for ; Fri, 2 Aug 2024 23:14:13 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id BAF581E9A for ; Fri, 2 Aug 2024 23:14:11 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1720523034.ac5f9575ad1fd7953d8c9c249ae1a0d0d7024e9b.sam@gentoo> Subject: [gentoo-commits] proj/gentoo-functions:master commit in: / X-VCS-Repository: proj/gentoo-functions X-VCS-Files: functions.sh X-VCS-Directories: / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: ac5f9575ad1fd7953d8c9c249ae1a0d0d7024e9b X-VCS-Branch: master Date: Fri, 2 Aug 2024 23:14:11 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 432bd080-1d38-49f0-be4c-46317b9a477a X-Archives-Hash: 09f80f1abc6769fe537454b267803761 commit: ac5f9575ad1fd7953d8c9c249ae1a0d0d7024e9b Author: Kerin Millar plushkava net> AuthorDate: Tue Jul 9 11:01:28 2024 +0000 Commit: Sam James gentoo 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 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()