You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/11/02 19:50:06 UTC
couch-stats commit: updated refs/heads/histogram-fun to 1bcffbd
Repository: couchdb-couch-stats
Updated Branches:
refs/heads/histogram-fun [created] 1bcffbdd2
update_histogram with timing of a function
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/commit/1bcffbdd
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/tree/1bcffbdd
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/diff/1bcffbdd
Branch: refs/heads/histogram-fun
Commit: 1bcffbdd260ac600336bb74db592b2481bb6a2e6
Parents: b368547
Author: Robert Newson <rn...@apache.org>
Authored: Sat Nov 1 16:32:16 2014 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Sun Nov 2 18:49:45 2014 +0000
----------------------------------------------------------------------
src/couch_stats.erl | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/blob/1bcffbdd/src/couch_stats.erl
----------------------------------------------------------------------
diff --git a/src/couch_stats.erl b/src/couch_stats.erl
index b4b3b22..59854e2 100644
--- a/src/couch_stats.erl
+++ b/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,
+ 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().