Class: TestProf::EventProf::Monitor::TopLevelTracker

Inherits:
BaseTracker
  • Object
show all
Defined in:
lib/test_prof/event_prof/monitor.rb

Instance Attribute Summary collapse

Attributes inherited from BaseTracker

#event

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ TopLevelTracker

Returns a new instance of TopLevelTracker.



22
23
24
25
26
# File 'lib/test_prof/event_prof/monitor.rb', line 22

def initialize(event)
  super
  @id = :"event_prof_monitor_#{event}"
  Thread.current[id] = 0
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



20
21
22
# File 'lib/test_prof/event_prof/monitor.rb', line 20

def id
  @id
end

Instance Method Details

#trackObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/test_prof/event_prof/monitor.rb', line 28

def track
  Thread.current[id] += 1
  res = nil
  begin
    res =
      if Thread.current[id] == 1
        super { yield }
      else
        yield
      end
  ensure
    Thread.current[id] -= 1
  end
  res
end