Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust_interval detects clock changes #44

Merged
merged 2 commits into from
Aug 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/exometer_report.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1227,8 +1227,9 @@ cancel_subscr_timers(Reporter) ->
_ = '_'}, [], ['$_']}])).

restart_subscr_timer(Key, Interval, T0) when is_integer(Interval) ->
TRef = erlang:send_after(adjust_interval(Interval, T0), self(),
subscr_timer_msg(Key, Interval, T0)),
{AdjInt, RptTime} = adjust_interval(Interval, T0),
TRef = erlang:send_after(AdjInt, self(),
subscr_timer_msg(Key, Interval, RptTime)),
ets:update_element(?EXOMETER_SUBS, Key,
[{#subscriber.t_ref, TRef}]);
restart_subscr_timer(_, _, _) ->
Expand All @@ -1239,9 +1240,10 @@ restart_batch_timer(Name, #reporter{name = Reporter,
case lists:keyfind(Name, #interval.name, Ints) of
#interval{time = Time, t_ref = OldTRef} = I when is_integer(Time) ->
cancel_timer(OldTRef),
TRef = erlang:send_after(
adjust_interval(Time, T0), self(),
batch_timer_msg(Reporter, Name, Time, T0)),
{Int, RptTime} = adjust_interval(Time, T0),
TRef = erlang:send_after(Int, self(),
batch_timer_msg(
Reporter, Name, Time, RptTime)),
ets:update_element(?EXOMETER_REPORTERS, Reporter,
[{#reporter.intervals,
lists:keyreplace(Name, #interval.name, Ints,
Expand All @@ -1254,7 +1256,13 @@ restart_batch_timer(Name, #reporter{name = Reporter,

adjust_interval(Time, T0) ->
T1 = os:timestamp(),
erlang:max(0, Time - tdiff(T1, T0)).
case tdiff(T1, T0) of
D when D > Time; D < 0 ->
%% Most likely due to clock adjustment
{Time, T1};
D ->
{D, T0}
end.

tdiff(T1, T0) ->
timer:now_diff(T1, T0) div 1000.
Expand Down