Module: Flows::Plugin::Profiler::Wrapper Private

Defined in:
lib/flows/plugin/profiler/wrapper.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Since:

  • 0.4.0

Class Method Summary collapse

Class Method Details

.make_instance_wrapper(method_name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/MethodLength

Since:

  • 0.4.0



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/flows/plugin/profiler/wrapper.rb', line 7

def make_instance_wrapper(method_name) # rubocop:disable Metrics/MethodLength
  Module.new.tap do |mod|
    mod.define_method(method_name) do |*args, &block| # rubocop:disable Metrics/MethodLength
      thread = Thread.current
      klass = self.class

      return super(*args, &block) unless thread[THREAD_VAR_FLAG]

      report = thread[THREAD_VAR_REPORT]
      report.add(:started, klass, :instance, method_name, nil)

      before = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_microsecond)
      super(*args, &block)
    ensure
      if before
        after = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_microsecond)
        report.add(:finished, klass, :instance, method_name, after - before)
      end
    end
  end
end

.make_singleton_wrapper(method_name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/MethodLength

Since:

  • 0.4.0



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/flows/plugin/profiler/wrapper.rb', line 29

def make_singleton_wrapper(method_name) # rubocop:disable Metrics/MethodLength
  Module.new.tap do |mod|
    mod.define_method(method_name) do |*args, &block| # rubocop:disable Metrics/MethodLength
      thread = Thread.current

      return super(*args, &block) unless thread[THREAD_VAR_FLAG]

      report = thread[THREAD_VAR_REPORT]
      report.add(:started, self, :singleton, method_name, nil)

      before = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_microsecond)
      super(*args, &block)
    ensure
      if before
        after = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_microsecond)
        report.add(:finished, self, :singleton, method_name, after - before)
      end
    end
  end
end