Module: CloseYourIt::Instrumenter

Defined in:
lib/closeyourit/instrumenter.rb

Overview

Cronometra blocchi/metodi con ‘CLOCK_MONOTONIC` e invia un `slow_method` se la durata supera la soglia. Gli argomenti sono inviati solo se `capture_method_arguments` (opt-in) — vedi SlowMethodEvent.

Class Method Summary collapse

Class Method Details

.measure(label, args: nil, kwargs: nil) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/closeyourit/instrumenter.rb', line 11

def measure(label, args: nil, kwargs: nil)
  location = caller_locations(1, 1)&.first
  start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  yield
ensure
  duration_ms = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000.0
  report(label, duration_ms, location, args: args, kwargs: kwargs)
end

.report(label, duration_ms, location = nil, args: nil, kwargs: nil) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/closeyourit/instrumenter.rb', line 20

def report(label, duration_ms, location = nil, args: nil, kwargs: nil)
  config = CloseYourIt.configuration
  return if duration_ms < config.slow_method_threshold_ms

  CloseYourIt.capture_event(
    SlowMethodEvent.new(label, duration_ms, location, config, args: args, kwargs: kwargs)
  )
end