You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/07/31 23:24:58 UTC

[10/50] folsom commit: updated refs/heads/import-master to 4824aec

Add safe histogram notify functions


Project: http://git-wip-us.apache.org/repos/asf/couchdb-folsom/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-folsom/commit/31a348ba
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-folsom/tree/31a348ba
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-folsom/diff/31a348ba

Branch: refs/heads/import-master
Commit: 31a348ba88fd6aa5d69a15995c8d4eaf6ecda0f1
Parents: 3732005
Author: Paul Oliver <pu...@gmail.com>
Authored: Wed Jun 12 09:18:24 2013 -0400
Committer: Paul Oliver <pu...@gmail.com>
Committed: Wed Jun 12 09:18:24 2013 -0400

----------------------------------------------------------------------
 src/folsom_metrics.erl        | 27 ++++++++++++++++++++++++++-
 test/folsom_erlang_checks.erl |  5 +++++
 2 files changed, 31 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-folsom/blob/31a348ba/src/folsom_metrics.erl
----------------------------------------------------------------------
diff --git a/src/folsom_metrics.erl b/src/folsom_metrics.erl
index a6245c0..40f66f2 100644
--- a/src/folsom_metrics.erl
+++ b/src/folsom_metrics.erl
@@ -64,7 +64,11 @@
          histogram_timed_update/3,
          histogram_timed_update/4,
          histogram_timed_begin/1,
-         histogram_timed_notify/1
+         histogram_timed_notify/1,
+         safely_histogram_timed_update/2,
+         safely_histogram_timed_update/3,
+         safely_histogram_timed_update/4,
+         safely_histogram_timed_notify/1
         ]).
 
 -include("folsom.hrl").
@@ -201,3 +205,24 @@ histogram_timed_notify({Name, Begin}) ->
     Now = os:timestamp(),
     Time = timer:now_diff(Now, Begin),
     ok = notify({Name, Time}).
+
+safely_histogram_timed_update(Name, Fun) ->
+    {Time, Value} = timer:tc(Fun),
+    _ = safely_notify({Name, Time}),
+    Value.
+
+safely_histogram_timed_update(Name, Fun, Args) ->
+    {Time, Value} = timer:tc(Fun, Args),
+    _ = safely_notify({Name, Time}),
+    Value.
+
+safely_histogram_timed_update(Name, Mod, Fun, Args) ->
+    {Time, Value} = timer:tc(Mod, Fun, Args),
+    _ = safely_notify({Name, Time}),
+    Value.
+
+safely_histogram_timed_notify({Name, Begin}) ->
+    Now = os:timestamp(),
+    Time = timer:now_diff(Now, Begin),
+    _ = safely_notify({Name, Time}),
+    ok.

http://git-wip-us.apache.org/repos/asf/couchdb-folsom/blob/31a348ba/test/folsom_erlang_checks.erl
----------------------------------------------------------------------
diff --git a/test/folsom_erlang_checks.erl b/test/folsom_erlang_checks.erl
index 6b92bb6..6ea9a5a 100644
--- a/test/folsom_erlang_checks.erl
+++ b/test/folsom_erlang_checks.erl
@@ -109,6 +109,11 @@ populate_metrics() ->
     meck:new(folsom_ets),
     meck:expect(folsom_ets, notify, fun(_Event) -> meck:exception(error, something_wrong_with_ets) end),
     {'EXIT', {something_wrong_with_ets, _}} = folsom_metrics:safely_notify({unknown_counter, {inc, 1}}),
+    ok = folsom_metrics:safely_histogram_timed_update(unknown_histogram, fun() -> ok end),
+    ok = folsom_metrics:safely_histogram_timed_update(unknown_histogram, fun(ok) -> ok end, [ok]),
+    3.141592653589793 = folsom_metrics:safely_histogram_timed_update(unknown_histogram, math, pi, []),
+    UnknownHistogramBegin = folsom_metrics:histogram_timed_begin(unknown_histogram),
+    ok = folsom_metrics:safely_histogram_timed_notify(UnknownHistogramBegin),
     meck:unload(folsom_ets),
 
     ok = folsom_metrics:notify({<<"gauge">>, 2}),