Module: Polyrun::Timing::Merge
- Defined in:
- lib/polyrun/timing/merge.rb
Overview
Merges per-shard timing JSON files (spec2 ยง2.4): path => wall seconds (float). Disjoint suites: values merged by taking the maximum per path when duplicates appear.
Class Method Summary collapse
Class Method Details
.merge_and_write(paths, output_path) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/polyrun/timing/merge.rb', line 27 def merge_and_write(paths, output_path) Polyrun::Debug.log_kv(merge_timing: "merge_and_write", input_count: paths.size, output_path: output_path) merged = Polyrun::Debug.time("Timing::Merge.merge_files") { merge_files(paths) } Polyrun::Debug.time("Timing::Merge.write JSON") { File.write(output_path, JSON.pretty_generate(merged)) } merged end |
.merge_files(paths) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/polyrun/timing/merge.rb', line 12 def merge_files(paths) merged = {} paths.each do |p| data = JSON.parse(File.read(p)) next unless data.is_a?(Hash) data.each do |file, sec| f = file.to_s t = sec.to_f merged[f] = merged.key?(f) ? [merged[f], t].max : t end end merged end |