@@ -218,10 +218,11 @@ def timing(stat, ms, opts={})
218218 # $statsd.time('account.activate') { @account.activate! }
219219 def time ( stat , opts = { } )
220220 opts = { :sample_rate => opts } if opts . is_a? Numeric
221- start = Time . now
221+ start = ( PROCESS_TIME_SUPPORTED ? Process . clock_gettime ( Process :: CLOCK_MONOTONIC ) : Time . now . to_f )
222222 return yield
223223 ensure
224- time_since ( stat , start , opts )
224+ finished = ( PROCESS_TIME_SUPPORTED ? Process . clock_gettime ( Process ::CLOCK_MONOTONIC ) : Time . now . to_f )
225+ timing ( stat , ( ( finished - start ) * 1000 ) . round , opts )
225226 end
226227 # Sends a value to be tracked as a set to the statsd server.
227228 #
@@ -237,7 +238,6 @@ def set(stat, value, opts={})
237238 send_stats stat , value , SET_TYPE , opts
238239 end
239240
240-
241241 # This method allows you to send custom service check statuses.
242242 #
243243 # @param [String] name Service check name
@@ -356,9 +356,10 @@ def close()
356356 DOT = "." . freeze
357357 DOUBLE_COLON = "::" . freeze
358358 UNDERSCORE = "_" . freeze
359+ PROCESS_TIME_SUPPORTED = ( RUBY_VERSION >= "2.1.0" )
359360
360361 private_constant :NEW_LINE , :ESC_NEW_LINE , :COMMA , :BLANK , :PIPE , :DOT ,
361- :DOUBLE_COLON , :UNDERSCORE
362+ :DOUBLE_COLON , :UNDERSCORE , :PROCESS_TIME_SUPPORTED
362363
363364 def escape_event_content ( msg )
364365 msg . gsub NEW_LINE , ESC_NEW_LINE
@@ -383,10 +384,6 @@ def escape_service_check_message(msg)
383384 escape_event_content ( msg ) . gsub ( 'm:' . freeze , 'm\:' . freeze )
384385 end
385386
386- def time_since ( stat , start , opts )
387- timing ( stat , ( ( Time . now - start ) * 1000 ) . round , opts )
388- end
389-
390387 def join_array_to_str ( str , array , joiner )
391388 array . each_with_index do |item , i |
392389 str << joiner unless i == 0
0 commit comments