module Datadog::Utils::Time

Common database-related utility functions.

Public Instance Methods

get_time() click to toggle source

Current monotonic time. Falls back to `now` if monotonic clock is not available.

@return [Float] in seconds, since some unspecified starting point

# File lib/ddtrace/utils/time.rb, line 15
def get_time
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
end
measure() { || ... } click to toggle source
# File lib/ddtrace/utils/time.rb, line 38
def measure
  before = get_time
  yield
  after = get_time
  after - before
end
now() click to toggle source

Current wall time.

@return [Time] current time object

# File lib/ddtrace/utils/time.rb, line 22
def now
  ::Time.now
end
now_provider=(block) click to toggle source

Overrides the implementation of `#now with the provided callable.

Overriding the method `#now` instead of indirectly calling `block` removes one level of method call overhead.

@param block [Proc] block that returns a `Time` object representing the current wall time

# File lib/ddtrace/utils/time.rb, line 34
def now_provider=(block)
  define_singleton_method(:now, &block)
end