Class: Capistrano::Measure::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/measure/timer.rb

Defined Under Namespace

Classes: Event

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTimer

Returns a new instance of Timer.



20
21
22
23
24
# File 'lib/capistrano/measure/timer.rb', line 20

def initialize
  @indent = 0
  @open_events = []
  @events = []
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



4
5
6
# File 'lib/capistrano/measure/timer.rb', line 4

def events
  @events
end

Instance Method Details

#report_eventsObject



44
45
46
47
48
49
50
51
# File 'lib/capistrano/measure/timer.rb', line 44

def report_events
  raise 'Performance measure is not completed' unless @open_events.empty?
  return to_enum(__callee__) unless block_given?

  (events + [Event.new]).each_cons(2) do |event, next_event|
    yield event unless event.start? && event.eq?(next_event)
  end
end

#start(event_name) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/capistrano/measure/timer.rb', line 26

def start(event_name)
  event = Event.new(event_name, :start, Time.now, @indent)
  @open_events << event
  @events << event
  @indent += 1

  event
end

#stop(event_name) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/capistrano/measure/timer.rb', line 35

def stop(event_name)
  event = close_event(event_name)
  @open_events.pop
  @events << event
  @indent = event.indent

  event
end