Class: Binpacker::ProgressDisplay
- Inherits:
-
Object
- Object
- Binpacker::ProgressDisplay
- Defined in:
- lib/binpacker/progress.rb
Constant Summary collapse
- CI_INTERVAL =
seconds between CI output lines
15
Instance Method Summary collapse
- #finish(worker_stats = []) ⇒ Object
-
#initialize(worker_count, tty: $stdout.tty?) ⇒ ProgressDisplay
constructor
A new instance of ProgressDisplay.
- #refresh ⇒ Object
- #summary(worker_stats) ⇒ Object
- #update(worker_id, done:, total:, file:, elapsed: 0.0) ⇒ Object
Constructor Details
#initialize(worker_count, tty: $stdout.tty?) ⇒ ProgressDisplay
Returns a new instance of ProgressDisplay.
7 8 9 10 11 12 13 14 15 |
# File 'lib/binpacker/progress.rb', line 7 def initialize(worker_count, tty: $stdout.tty?) @worker_count = worker_count @tty = tty @workers = Array.new(worker_count) { { done: 0, total: 0, file: "", elapsed: 0.0 } } @start = Time.now @last_ci_output = Time.at(Time.now.to_f - CI_INTERVAL) @lines_written = 0 @mutex = Mutex.new end |
Instance Method Details
#finish(worker_stats = []) ⇒ Object
35 36 37 38 39 |
# File 'lib/binpacker/progress.rb', line 35 def finish(worker_stats = []) return unless @tty redraw $stdout.puts end |
#refresh ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/binpacker/progress.rb', line 27 def refresh if @tty redraw else periodic_output end end |
#summary(worker_stats) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/binpacker/progress.rb', line 41 def summary(worker_stats) active = worker_stats.reject { |s| s[:files] == 0 && s[:examples] == 0 } return if active.empty? active.each_with_index do |s, i| t = format_time(s[:total_time]) wid = worker_stats.index(s) $stdout.puts " Worker #{wid}: #{s[:files]} files, #{t} | #{s[:examples]} examples, #{s[:passed]} passed" end total_files = active.sum { |s| s[:files] } total_time = active.sum { |s| s[:total_time] } total_examples = active.sum { |s| s[:examples] } times = active.map { |s| s[:total_time] } mean = total_time / active.size max_dev = times.map { |t| (t - mean).abs }.max dev_pct = mean > 0 ? (max_dev / mean * 100).round(1) : 0 $stdout.puts " ──" $stdout.puts " Total: #{total_files} files, #{format_time(total_time)} | #{total_examples} examples" $stdout.puts " Balance: max deviation #{format_time(max_dev)} (#{dev_pct}%)" end |
#update(worker_id, done:, total:, file:, elapsed: 0.0) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/binpacker/progress.rb', line 17 def update(worker_id, done:, total:, file:, elapsed: 0.0) @mutex.synchronize do w = @workers[worker_id] w[:done] = done w[:total] = total w[:file] = file w[:elapsed] = elapsed end end |