Class: DiyProf::Tracer

Inherits:
Object
  • Object
show all
Includes:
TimeHelpers
Defined in:
lib/diy_prof/lib/diy_prof/tracer.rb

Instance Method Summary collapse

Methods included from TimeHelpers

#cpu_time, #wall_time

Constructor Details

#initialize(reporter) ⇒ Tracer

Returns a new instance of Tracer.


5
6
7
8
9
10
11
12
# File 'lib/diy_prof/lib/diy_prof/tracer.rb', line 5

def initialize(reporter)
  @reporter = reporter
  @tracepoints = [:call, :return].collect do |event|
    TracePoint.new(event) do |trace|
      reporter.record(event, trace.method_id, cpu_time)
    end
  end
end

Instance Method Details

#disableObject


17
18
19
# File 'lib/diy_prof/lib/diy_prof/tracer.rb', line 17

def disable
  @tracepoints.each(&:disable)
end

#enableObject


13
14
15
# File 'lib/diy_prof/lib/diy_prof/tracer.rb', line 13

def enable
  @tracepoints.each(&:enable)
end

#resultObject


21
22
23
# File 'lib/diy_prof/lib/diy_prof/tracer.rb', line 21

def result
  @reporter.result
end