Class: PrometheusExporter::Instrumentation::MethodProfiler
- Inherits:
-
Object
- Object
- PrometheusExporter::Instrumentation::MethodProfiler
- Defined in:
- lib/prometheus_exporter/instrumentation/method_profiler.rb
Class Method Summary collapse
- .clear ⇒ Object
- .patch(klass, methods, name, instrument:) ⇒ Object
- .start(transfer = nil) ⇒ Object
- .stop ⇒ Object
- .transfer ⇒ Object
Class Method Details
.clear ⇒ Object
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 |
.stop ⇒ Object
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 |
.transfer ⇒ Object
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 |