This is an automated email from the ASF dual-hosted git repository. vatamane pushed a commit to branch replace-folsom in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 7edffa36a3a996afb9095a89dbb877ff6e357ea4 Author: Nick Vatamaniuc <[email protected]> AuthorDate: Tue Jul 18 00:55:31 2023 -0400 [fixup|histogram] cleanup comments, add extra constant checks --- src/couch_stats/src/couch_stats_histogram.erl | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/couch_stats/src/couch_stats_histogram.erl b/src/couch_stats/src/couch_stats_histogram.erl index 61d88ad08..5f5d35179 100644 --- a/src/couch_stats/src/couch_stats_histogram.erl +++ b/src/couch_stats/src/couch_stats_histogram.erl @@ -65,7 +65,7 @@ % % In practice, the time window would be used as a circular buffer. The time % parameter to the update/3 function might be the system monotonic clock time -% and then the histogram time index is compuated as `Time rem TimeWindow`. So, +% and then the histogram time index is computed as `Time rem TimeWindow`. So, % as the monotonic time is advancing forward, the histogram time index will % loop around. This comes with a minor annoynance of having to allocate a % larger time window to accomodate some process which cleans stale (expired) @@ -116,6 +116,9 @@ get_bin_boundaries/0 ]). +% When updating constants comment out this directive, otherwise it might +% prevent module loading with the intermediate/new constants values. +% -on_load(check_constants/0). -define(FLOAT_SIZE, 64). @@ -200,6 +203,14 @@ get_bin_boundaries() -> % if some are not updated module loading will throw an error. % check_constants() -> + case is_float(?MIN_VAL) of + true -> ok; + false -> error({min_val_is_not_a_float, ?MIN_VAL}) + end, + case ?MIN_VAL > 0.0 of + true -> ok; + false -> error({min_val_must_be_positive, ?MIN_VAL}) + end, case calc_bin_count() of ?BIN_COUNT -> ok; OtherBinCount -> error({bin_count_stale, ?BIN_COUNT, OtherBinCount}) @@ -238,8 +249,7 @@ bin_middle(Index) when is_integer(Index), Index >= 1, Index =< ?BIN_COUNT -> BiasedIndex = Index - ?BIN_OFFSET, % 1 is the sign bit BinBitSize = ?FLOAT_SIZE - 1 - ?INDEX_BITS, - % Shift left 1 bit less than we do in bin_max, which is effectively - % is Max / 2. + % Shift left 1 bit less than we do in bin_max, which is effectively Max/2 <<Mid/float>> = <<0:1, BiasedIndex:?INDEX_BITS, (1 bsl (BinBitSize - 1)):BinBitSize>>, Mid. @@ -419,10 +429,8 @@ calculated_constants_test() -> get_bin_boundaries_test() -> Boundaries = get_bin_boundaries(), ?assertEqual(?BIN_COUNT, length(Boundaries)), - %io:format(standard_error, "~n--- bin boundaries ---~n~n", []), lists:foreach( fun({Min, Max}) -> - %io:format(standard_error, "[~p ~p]~n", [Min, Max]), ?assert(Min < Max) end, Boundaries
