couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject couch-stats commit: updated refs/heads/master to 1bcffbd
Date Sun, 02 Nov 2014 20:57:25 GMT
Repository: couchdb-couch-stats
Updated Branches:
  refs/heads/master b36854774 -> 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/master
Commit: 1bcffbdd260ac600336bb74db592b2481bb6a2e6
Parents: b368547
Author: Robert Newson <rnewson@apache.org>
Authored: Sat Nov 1 16:32:16 2014 +0000
Committer: Robert Newson <rnewson@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().


Mime
View raw message