Fix dbufstats_001_pos

Implement a new helper within_tolerance to test if a value
is within range of a target.

Because the dbufstats and dbufs kstat file are being read
at slightly different times, it is possible for stats to be
slightly off. Use within_tolerance to determine if the value
is "close enough" to the target.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Closes #7239 
Closes #7266
This commit is contained in:
Giuseppe Di Natale
2018-03-07 09:53:04 -08:00
committed by Brian Behlendorf
parent 639b18944a
commit a07ad58847
2 changed files with 28 additions and 4 deletions
+23
View File
@@ -42,6 +42,29 @@ function within_percent
return 1
}
#
# Return 0 if value is within +/-tolerance of target.
# Return 1 if value exceeds our tolerance.
# For use like this:
#
# Do $action if value is within the tolerance from target passed in:
# within_tolerance VAL TAR TOL && $action
# Do $action if value surpasses the tolerance from target passed in:
# within_tolerance VAL TAR TOL || $action
#
function within_tolerance #value #target #tolerance
{
typeset val=$1
typeset target=$2
typeset tol=$3
typeset diff=$((abs(val - target)))
log_note "Checking if $val is within +/-$tol of $target (diff: $diff)"
((diff <= tol)) && return 0
return 1
}
#
# Return 0 if the human readable string of the form <value>[suffix] can
# be converted to bytes. Allow suffixes are shown in the table below.