Class: Timings
- Inherits:
-
Object
- Object
- Timings
- Defined in:
- action/lib/timings.rb
Overview
Collects monotonic elapsed timings for the GitHub Actions step summary.
Instance Method Summary collapse
- #finish(phase) ⇒ Object
-
#initialize(clock: Process) ⇒ Timings
constructor
A new instance of Timings.
- #measure(phase) ⇒ Object
- #start(phase) ⇒ Object
- #summary_lines ⇒ Object
Constructor Details
#initialize(clock: Process) ⇒ Timings
Returns a new instance of Timings.
5 6 7 8 9 |
# File 'action/lib/timings.rb', line 5 def initialize(clock: Process) @clock = clock @starts = {} @elapsed = {} end |
Instance Method Details
#finish(phase) ⇒ Object
15 16 17 18 19 20 |
# File 'action/lib/timings.rb', line 15 def finish(phase) started = @starts.delete(phase) return unless started @elapsed[phase] = now - started end |
#measure(phase) ⇒ Object
22 23 24 25 26 27 |
# File 'action/lib/timings.rb', line 22 def measure(phase) started = now yield ensure @elapsed[phase] = now - started end |
#start(phase) ⇒ Object
11 12 13 |
# File 'action/lib/timings.rb', line 11 def start(phase) @starts[phase] = now end |
#summary_lines ⇒ Object
29 30 31 32 33 34 |
# File 'action/lib/timings.rb', line 29 def summary_lines return [] if @elapsed.empty? ["", "### Timings", "", "| Phase | Duration |", "| --- | --- |"] + @elapsed.map { |phase, seconds| "| #{phase} | #{format('%.1fs', seconds)} |" } end |