Add new timed update begin/notify functions
diff --git a/src/folsom_metrics.erl b/src/folsom_metrics.erl
index db0936f..621fb7d 100644
--- a/src/folsom_metrics.erl
+++ b/src/folsom_metrics.erl
@@ -55,7 +55,9 @@
get_history_values/2,
histogram_timed_update/2,
histogram_timed_update/3,
- histogram_timed_update/4
+ histogram_timed_update/4,
+ histogram_timed_begin/1,
+ histogram_timed_notify/1
]).
-include("folsom.hrl").
@@ -163,3 +165,11 @@
{Time, Value} = timer:tc(Mod, Fun, Args),
ok = notify({Name, Time}),
Value.
+
+histogram_timed_begin(Name) ->
+ {Name, os:timestamp()}.
+
+histogram_timed_notify({Name, Begin}) ->
+ Now = os:timestamp(),
+ Time = timer:now_diff(Now, Begin),
+ ok = notify({Name, Time}).
diff --git a/test/folsom_erlang_checks.erl b/test/folsom_erlang_checks.erl
index c35d27a..101f78c 100644
--- a/test/folsom_erlang_checks.erl
+++ b/test/folsom_erlang_checks.erl
@@ -56,6 +56,7 @@
ok = folsom_metrics:new_histogram(nonea, none, 5000),
ok = folsom_metrics:new_histogram(timed, none, 5000),
+ ok = folsom_metrics:new_histogram(timed2, none, 5000),
ok = folsom_metrics:new_history(<<"history">>),
ok = folsom_metrics:new_meter(meter),
@@ -81,7 +82,7 @@
%% check a server got started for the spiral metric
1 = length(supervisor:which_children(folsom_sample_slide_sup)),
- 13 = length(folsom_metrics:get_metrics()),
+ 14 = length(folsom_metrics:get_metrics()),
?debugFmt("~n~nmetrics: ~p~n", [folsom_metrics:get_metrics()]).
@@ -103,6 +104,9 @@
3.141592653589793 = folsom_metrics:histogram_timed_update(timed, math, pi, []),
+ Begin = folsom_metrics:histogram_timed_begin(timed2),
+ folsom_metrics:histogram_timed_notify(Begin),
+
PopulateDuration = fun() ->
ok = folsom_metrics:notify_existing_metric(duration, timer_start, duration),
timer:sleep(10),
@@ -171,6 +175,9 @@
List = folsom_metrics:get_metric_value(timed),
?debugFmt("timed update value: ~p", [List]),
+ List2 = folsom_metrics:get_metric_value(timed2),
+ ?debugFmt("timed update value begin/end: ~p", [List2]),
+
1 = length(folsom_metrics:get_metric_value(<<"history">>)),
1 = length(folsom_metrics:get_metric_value(historya)),
@@ -209,7 +216,7 @@
delete_metrics() ->
- 15 = length(ets:tab2list(?FOLSOM_TABLE)),
+ 16 = length(ets:tab2list(?FOLSOM_TABLE)),
ok = folsom_metrics:delete_metric(counter),
ok = folsom_metrics:delete_metric(<<"gauge">>),
@@ -224,6 +231,7 @@
ok = folsom_metrics:delete_metric(nonea),
ok = folsom_metrics:delete_metric(timed),
+ ok = folsom_metrics:delete_metric(timed2),
ok = folsom_metrics:delete_metric(testcounter),
ok = ensure_meter_tick_exists(2),