Skip to content

Commit

Permalink
Merge branch 'timing-funcs'
Browse files Browse the repository at this point in the history
  • Loading branch information
amtal committed Apr 29, 2011
2 parents 3732dd6 + 0000648 commit 47f631a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
.eunit/
deps/
doc/
ebin/
19 changes: 9 additions & 10 deletions src/folsom_metrics.erl
Expand Up @@ -106,20 +106,19 @@ get_histogram_sample(Name) ->
get_history_values(Name, Count) ->
folsom_event:get_history_values(Name, Count).

%% @doc Fun/funcall instrumentation.
%%
%% If an exception occurs, time is not logged.
histogram_timed_update(Name, Fun) ->
Start = folsom_utils:now_epoch_micro(),
Fun(),
Stop = folsom_utils:now_epoch_micro(),
notify({Name, Stop - Start}).
histogram_timed_update(Name, Fun, []).

histogram_timed_update(Name, Fun, Args) ->
Start = folsom_utils:now_epoch_micro(),
erlang:apply(Fun, Args),
Result = erlang:apply(Fun, Args),
Stop = folsom_utils:now_epoch_micro(),
notify({Name, Stop - Start}).
notify({Name, Stop - Start}),
Result.

histogram_timed_update(Name, Mod, Fun, Args) ->
Start = folsom_utils:now_epoch_micro(),
erlang:apply(Mod, Fun, Args),
Stop = folsom_utils:now_epoch_micro(),
notify({Name, Stop - Start}).
Run = fun()->erlang:apply(Mod, Fun, Args) end,
histogram_timed_update(Name, Run, []).
39 changes: 39 additions & 0 deletions test/folsom_metric_checks.erl
@@ -0,0 +1,39 @@
%%%
%%% Copyright 2011, Boundary
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.
%%% You may obtain a copy of the License at
%%%
%%% http://www.apache.org/licenses/LICENSE-2.0
%%%
%%% Unless required by applicable law or agreed to in writing, software
%%% distributed under the License is distributed on an "AS IS" BASIS,
%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%%% See the License for the specific language governing permissions and
%%% limitations under the License.
%%%


%%%-------------------------------------------------------------------
%%% File: folsom_metric_checks.erl
%%% @author amtal <alex.kropivny@gmail.com>
%%% @doc External interface tests.
%%% @end
%%%------------------------------------------------------------------

-module(folsom_metric_checks).

-include_lib("eunit/include/eunit.hrl").

-export([ histograms/0
]).

-define(FM, folsom_metrics).

histograms() ->
ok = ?FM:new_histogram(funcalls,uniform),
5 = ?FM:histogram_timed_update(funcalls, fun()->abs(-5) end),
5 = ?FM:histogram_timed_update(funcalls, fun(X)->abs(X) end, [-5]),
5 = ?FM:histogram_timed_update(funcalls, erlang, abs, [-5]),
[_,_,_] = ?FM:get_histogram_sample(funcalls).
2 changes: 2 additions & 0 deletions test/folsom_tests.erl
Expand Up @@ -39,6 +39,8 @@ run_test() ->
ibrowse:stop(),

folsom_erlang_checks:delete_metrics(),

folsom_metric_checks:histograms(),

folsom:stop().

Expand Down

0 comments on commit 47f631a

Please sign in to comment.