Class: Dash::Timings

Inherits:
Object
  • Object
show all
Defined in:
lib/dash/timings.rb

Overview

Wall-clock accounting for a deploy, printed under "Finished all in". The total on its own says nothing about where the time went — a serialised boot, a slow pull, or a proxy waiting on a health check all look the same from the outside.

Entries land in start order and carry a depth, so a parent phase (Boot) prints above the host entries it wraps even though the hosts finish first. Boot runs one thread per host, so every mutation is behind the mutex.

Defined Under Namespace

Classes: Entry

Instance Method Summary collapse

Constructor Details

#initializeTimings

Returns a new instance of Timings.



11
12
13
14
# File 'lib/dash/timings.rb', line 11

def initialize
  @entries = []
  @mutex = Mutex.new
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/dash/timings.rb', line 28

def any?
  @mutex.synchronize { @entries.any? }
end

#linesObject



32
33
34
35
36
37
38
39
# File 'lib/dash/timings.rb', line 32

def lines
  @mutex.synchronize do
    @entries.map do |entry|
      line = format("  %s%-36s %6.1fs", "  " * entry.depth, entry.name, entry.seconds.to_f)
      entry.detail ? "#{line} (#{entry.detail})" : line
    end
  end
end

#phase(name, depth: 0) ⇒ Object

Times the block. The entry is yielded so the block can annotate it — a boot can say how long of its total was spent waiting for the container to become healthy.



18
19
20
21
22
23
24
25
26
# File 'lib/dash/timings.rb', line 18

def phase(name, depth: 0)
  entry = Entry.new(name, nil, nil, depth)
  @mutex.synchronize { @entries << entry }
  started = clock

  yield entry
ensure
  entry.seconds = clock - started
end