Browse files

Split timing/3 into timing/3 and timing_now/3

  • Loading branch information...
1 parent 652c189 commit 8e6617f122da8d11f454db64195baaf602c53259 @lpgauth committed Sep 9, 2011
Showing with 12 additions and 6 deletions.
  1. +4 −1 README.md
  2. +8 −5 src/statsderl.erl
View
5 README.md
@@ -12,8 +12,11 @@
statsderl:decrement("test.decrement", 1, 0.5).
#### Timing
+ statsderl:timing("test.timing", 5, 0.5).
+
+#### Timing now
Timestamp = erlang:now(),
- statsderl:timing("test.timing", Timestamp, 0.5).
+ statsderl:timing_now("test.timing", Timestamp, 0.5).
View
13 src/statsderl.erl
@@ -15,7 +15,7 @@
%% API Function Exports
%% ------------------------------------------------------------------
--export([start_link/0, increment/3, decrement/3, timing/3]).
+-export([start_link/0, increment/3, decrement/3, timing/3, timing_now/3]).
%% ------------------------------------------------------------------
%% gen_server Function Exports
@@ -39,10 +39,13 @@ decrement(Key, Magnitude, SampleRate) ->
Stats = io_lib:format("~s:-~B|c|@~f", [Key, Magnitude, SampleRate]),
udp_send(Stats, SampleRate).
-timing(Key, Timestamp, SampleRate) ->
- Timing = timer:now_diff(erlang:now(), Timestamp) div 1000,
- Stats = io_lib:format("~s:~B|ms|@~f", [Key, Timing, SampleRate]),
- udp_send(Stats, SampleRate).
+timing(Key, Value, SampleRate) ->
+ Stats = io_lib:format("~s:~B|ms|@~f", [Key, Value, SampleRate]),
+ udp_send(Stats, SampleRate).
+
+timing_now(Key, Timestamp, SampleRate) ->
+ Value = timer:now_diff(erlang:now(), Timestamp) div 1000,
+ timing(Key, Value, SampleRate).
%% ------------------------------------------------------------------
%% gen_server Function Definitions

0 comments on commit 8e6617f

Please sign in to comment.