Class: Autoproj::Ops::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/autoproj/ops/stats.rb

Overview

Computes per-package statistics

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sanitizer: Autoproj::Stats::Sanitizer.new) ⇒ Stats

Returns a new instance of Stats.



9
10
11
# File 'lib/autoproj/ops/stats.rb', line 9

def initialize(sanitizer: Autoproj::Stats::Sanitizer.new)
    @sanitizer = sanitizer
end

Instance Attribute Details

#sanitizerObject (readonly)

Returns the value of attribute sanitizer.



7
8
9
# File 'lib/autoproj/ops/stats.rb', line 7

def sanitizer
  @sanitizer
end

Instance Method Details

#compute_package_stats(pkg) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/autoproj/ops/stats.rb', line 36

def compute_package_stats(pkg)
    if pkg.importer
        if stats_generator = find_generator_for_importer(pkg.importer)
            stats_generator.(pkg)
        else
            Autoproj.warn "no stats generator for #{pkg.name} (#{pkg.importer.class})"
        end
    else
        Autoproj.warn "no importer for #{pkg.name}"
    end
end

#find_generator_for_importer(importer) ⇒ Object



48
49
50
51
52
# File 'lib/autoproj/ops/stats.rb', line 48

def find_generator_for_importer(importer)
    if importer.class == Autobuild::Git
        return Autoproj::Stats::Git.new(sanitizer: sanitizer)
    end
end

#process(packages, parallel: 1) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/autoproj/ops/stats.rb', line 13

def process(packages, parallel: 1)
    executor = Concurrent::FixedThreadPool.new(parallel, max_length: 0)
    result = Hash.new

    futures = packages.map do |pkg|
        [pkg, Concurrent::Future.execute(executor: executor) { compute_package_stats(pkg) }]
    end
    futures.inject(Hash.new) do |h, (pkg, future)|
        if stats = future.value
            h[pkg] = stats
        elsif future.reason.kind_of?(Exception)
            raise future.reason
        else
            pkg.error "%s: failed, #{future.reason}"
        end
        h
    end

ensure
    executor.shutdown
    executor.wait_for_termination
end