Module: Datadog::Utils::Time

Includes:
Kernel
Defined in:
lib/ddtrace/utils/time.rb

Overview

Common database-related utility functions.

Class Method Summary collapse

Class Method Details

.get_timeFloat

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

Returns:

  • (Float)

    in seconds, since some unspecified starting point



15
16
17
# File 'lib/ddtrace/utils/time.rb', line 15

def get_time
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
end

.measureObject



38
39
40
41
42
43
# File 'lib/ddtrace/utils/time.rb', line 38

def measure
  before = get_time
  yield
  after = get_time
  after - before
end

.nowTime

Current wall time.

Returns:

  • (Time)

    current time object



22
23
24
# File 'lib/ddtrace/utils/time.rb', line 22

def now
  ::Time.now
end

.now_provider=(block) ⇒ Object

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.

Parameters:

  • block (Proc)

    block that returns a ‘Time` object representing the current wall time



34
35
36
# File 'lib/ddtrace/utils/time.rb', line 34

def now_provider=(block)
  define_singleton_method(:now, &block)
end