Sha256: 3868e13a77e2391b3a15c4346e7ad0338c2b75b9e4538933e6afcd6be5a55f57

Contents?: true

Size: 1.82 KB

Versions: 5

Compression:

Stored size: 1.82 KB

Contents

require 'time'

module Autobuild
    # Parse and manipulate the information stored in a build log file (usually
    # in prefix/log/stats.log)
    class BuildLogfile
        Entry = Struct.new :package, :phase, :start_time, :duration

        attr_reader :by_package, :by_phase

        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

        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

        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
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
autobuild-1.24.0 lib/autobuild/build_logfile.rb
autobuild-1.23.1 lib/autobuild/build_logfile.rb
autobuild-1.23.0 lib/autobuild/build_logfile.rb
autobuild-1.22.1 lib/autobuild/build_logfile.rb
autobuild-1.22.0 lib/autobuild/build_logfile.rb