Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
update_histogram with timing of a function
  • Loading branch information
rnewson committed Nov 2, 2014
1 parent b368547 commit 1bcffbdd260ac600336bb74db592b2481bb6a2e6
Showing 1 changed file with 13 additions and 2 deletions.
@@ -87,8 +87,19 @@ decrement_counter(Name) ->
decrement_counter(Name, Value) ->
notify(Name, {dec, Value}).

-spec update_histogram(any(), number()) -> response().
update_histogram(Name, Value) ->
-spec update_histogram(any(), number()) -> response();
(any(), function()) -> any().
update_histogram(Name, Fun) when is_function(Fun, 0) ->
Begin = os:timestamp(),
Result = Fun(),
Duration = timer:now_diff(os:timestamp(), Begin) div 1000,
case notify(Name, Duration) of
ok ->
Result;
{error, unknown_metric} ->
throw({unknown_metric, Name})
end;
update_histogram(Name, Value) when is_number(Value) ->
notify(Name, Value).

-spec update_gauge(any(), number()) -> response().

0 comments on commit 1bcffbd

Please sign in to comment.