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 Logging

#finish, #start

Constructor Details

#initialize(logger, identifier) ⇒ Aggregate

Returns a new instance of Aggregate.



5
6
7
8
# File 'lib/puppet/util/profiler/aggregate.rb', line 5

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

Instance Method Details

#do_finish(context, description, metric_id) ⇒ Object



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

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

#do_start(description, metric_id) ⇒ Object



18
19
20
# File 'lib/puppet/util/profiler/aggregate.rb', line 18

def do_start(description, metric_id)
  super(description, metric_id)
end


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

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



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

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



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

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



40
41
42
# File 'lib/puppet/util/profiler/aggregate.rb', line 40

def values
  @metrics_hash
end