Github user kxepal commented on a diff in the pull request:
https://github.com/apache/couchdb-couch-stats/pull/3#discussion_r19714068
--- Diff: src/couch_stats.erl ---
@@ -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,
--- End diff --
That's actually what `timer:tc` does:
https://github.com/erlang/otp/blob/maint/lib/stdlib/src/timer.erl#L192
So may be:
```
{Duration, Result} = timer:tc(Fun),
case notify(Name, Duration div 1000) of
ok ->
Result;
{error, unknown_metric} ->
throw({unknown_metric, Name})
end;
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---