Class: Puppet::Util::Profiler::Aggregate

Inherits:
WallClock show all
Defined in:
lib/puppet/util/profiler/aggregate.rb

Defined Under Namespace

Classes: Metric, Timer

Instance Method Summary collapse

Methods inherited from WallClock

#do_start

Methods inherited from Logging

#finish, #start

Constructor Details

#initialize(logger, identifier) ⇒ Aggregate

Returns a new instance of Aggregate.



7
8
9
10
# File 'lib/puppet/util/profiler/aggregate.rb', line 7

def initialize(logger, identifier)
  super(logger, identifier)
  @metrics_hash = Metric.new
end

Instance Method Details

#do_finish(context, description, metric_id) ⇒ Object



20
21
22
23
24
# File 'lib/puppet/util/profiler/aggregate.rb', line 20

def do_finish(context, description, metric_id)
  result = super(context, description, metric_id)
  update_metric(@metrics_hash, metric_id, result[:time])
  result
end


42
43
44
45
46
47
# File 'lib/puppet/util/profiler/aggregate.rb', line 42

def print_metrics(metrics_hash, prefix)
  metrics_hash.sort_by { |_k, v| v.time }.reverse_each do |k, v|
    @logger.call("#{prefix}#{k}: #{v.time} s (#{v.count} calls)")
    print_metrics(metrics_hash[k], "#{prefix}#{k} -> ")
  end
end

#shutdownObject



12
13
14
15
16
17
18
# File 'lib/puppet/util/profiler/aggregate.rb', line 12

def shutdown
  super
  @logger.call("AGGREGATE PROFILING RESULTS:")
  @logger.call("----------------------------")
  print_metrics(@metrics_hash, "")
  @logger.call("----------------------------")
end

#update_metric(metrics_hash, metric_id, time) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/puppet/util/profiler/aggregate.rb', line 26

def update_metric(metrics_hash, metric_id, time)
  first, *rest = *metric_id
  if first
    m = metrics_hash[first]
    m.increment
    m.add_time(time)
    if rest.count > 0
      update_metric(m, rest, time)
    end
  end
end

#valuesObject



38
39
40
# File 'lib/puppet/util/profiler/aggregate.rb', line 38

def values
  @metrics_hash
end