Verify increment is all 0s before applying drop

This commit is contained in:
Diana Corbacho 2016-11-09 10:53:36 +00:00 committed by kjnilsson
parent c3cfc4ace4
commit 35085496e0
2 changed files with 23 additions and 4 deletions

View File

@ -202,12 +202,16 @@ add_element(TS, Evt, #slide{last = Last, size = Sz, incremental = true,
buf1 = Buf1} = Slide, Wrap) ->
N1 = N+1,
Total = add_to_total(Evt, Total0),
case Buf1 of
[{_, Total}, drop | Tail] ->
%% Total could be the same as the last sample, by adding and substracting
%% the same amout to the totals. That is not strictly a drop, but should
%% generate new samples.
%% I.e. 0, 0, -14, 14 (total = 0, samples = 14, -14, 0, drop)
case {is_zeros(Evt), Buf1} of
{true, [{_, Total}, drop | Tail]} ->
%% Memory optimisation
Slide#slide{buf1 = [{TS, Total}, drop | Tail],
last = TS};
[{_, Total} | Tail] ->
{true, [{_, Total} | Tail]} ->
%% Memory optimisation
Slide#slide{buf1 = [{TS, Total}, drop | Tail],
last = TS};
@ -269,6 +273,21 @@ add_to_total({A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14,
B9 + A9, B10 + A10, B11 + A11, B12 + A12, B13 + A13, B14 + A14, B15 + A15, B16 + A16,
B17 + A17, B18 + A18, B19 + A19}.
is_zeros({0}) ->
true;
is_zeros({0, 0}) ->
true;
is_zeros({0, 0, 0}) ->
true;
is_zeros({0, 0, 0, 0, 0, 0, 0}) ->
true;
is_zeros({0, 0, 0, 0, 0, 0, 0, 0}) ->
true;
is_zeros({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) ->
true;
is_zeros(_) ->
false.
add_ret(false, _, Slide) ->
Slide;
add_ret(true, Flag, Slide) ->

View File

@ -147,7 +147,7 @@ foldl_incremental_test(_Config) ->
prop_foldl_incremental() ->
?FORALL({Elements, Int, Sleep}, {non_empty(elements_gen()), choose(1,9), choose(1,9)},
begin
Slide = exometer_slide:new(1000, [{interval, Int},
Slide = exometer_slide:new(60 * 1000, [{interval, Int},
{incremental, true}]),
Slide1 = lists:foldl(fun(E, Acc) ->
%% sometimes the data will be within the intervals