Class: Autobuild::BuildLogfile
- Inherits:
-
Object
- Object
- Autobuild::BuildLogfile
- Defined in:
- lib/autobuild/build_logfile.rb
Overview
Parse and manipulate the information stored in a build log file (usually in prefix/log/stats.log)
Defined Under Namespace
Classes: Entry
Instance Attribute Summary collapse
-
#by_package ⇒ Object
readonly
Returns the value of attribute by_package.
-
#by_phase ⇒ Object
readonly
Returns the value of attribute by_phase.
Class Method Summary collapse
Instance Method Summary collapse
- #diff(other) ⇒ Object
-
#initialize(entries = Array.new) ⇒ BuildLogfile
constructor
A new instance of BuildLogfile.
Constructor Details
#initialize(entries = Array.new) ⇒ BuildLogfile
Returns a new instance of BuildLogfile.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/autobuild/build_logfile.rb', line 11 def initialize(entries = Array.new) @entries = entries.dup @by_package = Hash.new entries.each do |e| package = (by_package[e.package] ||= Hash.new(0)) package[e.phase] += e.duration end @by_phase = Hash.new entries.each do |e| package = (by_phase[e.phase] ||= Hash.new(0)) package[e.package] += e.duration end end |
Instance Attribute Details
#by_package ⇒ Object (readonly)
Returns the value of attribute by_package.
9 10 11 |
# File 'lib/autobuild/build_logfile.rb', line 9 def by_package @by_package end |
#by_phase ⇒ Object (readonly)
Returns the value of attribute by_phase.
9 10 11 |
# File 'lib/autobuild/build_logfile.rb', line 9 def by_phase @by_phase end |
Class Method Details
.parse(file) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/autobuild/build_logfile.rb', line 42 def self.parse(file) entries = File.readlines(file).map do |line| line = line.strip next if line.empty? cols = line.split(/\s+/) date = cols.shift time = cols.shift start_time = Time.parse("#{date} #{time}") duration = Float(cols.pop) phase = cols.pop package = cols.join(" ") Entry.new(package, phase, start_time, duration) end new(entries) end |
Instance Method Details
#diff(other) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/autobuild/build_logfile.rb', line 26 def diff(other) result = [] by_package.each do |pkg_name, phases| other_phases = other.by_package[pkg_name] next unless other_phases phases.each do |phase, duration| next unless other_phases.key?(phase) other_duration = other_phases[phase] result << Entry.new(pkg_name, phase, nil, other_duration - duration) end end BuildLogfile.new(result) end |