Class: PrometheusExporter::Instrumentation::MethodProfiler

Inherits:
Object
  • Object
show all
Defined in:
lib/prometheus_exporter/instrumentation/method_profiler.rb

Class Method Summary collapse

Class Method Details

.clearObject



29
30
31
# File 'lib/prometheus_exporter/instrumentation/method_profiler.rb', line 29

def self.clear
  Thread.current[:_method_profiler] = nil
end

.patch(klass, methods, name, instrument:) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/prometheus_exporter/instrumentation/method_profiler.rb', line 7

def self.patch(klass, methods, name, instrument:)
  if instrument == :alias_method
    patch_using_alias_method(klass, methods, name)
  elsif instrument == :prepend
    patch_using_prepend(klass, methods, name)
  else
    raise ArgumentError, "instrument must be :alias_method or :prepend"
  end
end

.start(transfer = nil) ⇒ Object



23
24
25
26
27
# File 'lib/prometheus_exporter/instrumentation/method_profiler.rb', line 23

def self.start(transfer = nil)
  Thread.current[:_method_profiler] = transfer || {
    __start: Process.clock_gettime(Process::CLOCK_MONOTONIC)
  }
end

.stopObject



33
34
35
36
37
38
39
40
41
# File 'lib/prometheus_exporter/instrumentation/method_profiler.rb', line 33

def self.stop
  finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  if data = Thread.current[:_method_profiler]
    Thread.current[:_method_profiler] = nil
    start = data.delete(:__start)
    data[:total_duration] = finish - start
  end
  data
end

.transferObject



17
18
19
20
21
# File 'lib/prometheus_exporter/instrumentation/method_profiler.rb', line 17

def self.transfer
  result = Thread.current[:_method_profiler]
  Thread.current[:_method_profiler] = nil
  result
end