Skip to content

Commit 3e330c5

Browse files
committed
Cache value of os:timestamp() in basho_bench_stats:handle_cast()
1 parent 0faae29 commit 3e330c5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/basho_bench_stats.erl

+4-3
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,15 @@ handle_call({op, Op, {error, Reason}, _ElapsedUs}, _From, State) ->
149149
{reply, ok, State#state { errors_since_last_report = true }}.
150150

151151
handle_cast({Op, {ok, Units}, ElapsedUs}, State = #state{last_write_time = LWT, report_interval = RI}) ->
152-
TimeSinceLastReport = timer:now_diff(os:timestamp(), LWT) / 1000, %% To get the diff in seconds
153-
TimeSinceLastWarn = timer:now_diff(os:timestamp(), State#state.last_warn) / 1000,
152+
Now = os:timestamp(),
153+
TimeSinceLastReport = timer:now_diff(Now, LWT) / 1000, %% To get the diff in seconds
154+
TimeSinceLastWarn = timer:now_diff(Now, State#state.last_warn) / 1000,
154155
if
155156
TimeSinceLastReport > (RI * 2) andalso TimeSinceLastWarn > ?WARN_INTERVAL ->
156157
?WARN("basho_bench_stats has not reported in ~.2f milliseconds\n", [TimeSinceLastReport]),
157158
{message_queue_len, QLen} = process_info(self(), message_queue_len),
158159
?WARN("stats process mailbox size = ~w\n", [QLen]),
159-
NewState = State#state{last_warn = os:timestamp()};
160+
NewState = State#state{last_warn = Now};
160161
true ->
161162
NewState = State
162163
end,

0 commit comments

Comments
 (0)