Sha256: fe4b65bbc94c713fbe3ba9d414b0cce2185a964736fc81be8993c2d213d5eea7

Contents?: true

Size: 811 Bytes

Versions: 57

Compression:

Stored size: 811 Bytes

Contents

require 'monitor'

Puppet::Util::Instrumentation.new_listener(:performance) do

  attr_reader :samples

  def initialize
    @samples = {}.extend(MonitorMixin)
  end

  def notify(label, event, data)
    return if event == :start

    duration = data[:finished] - data[:started]
    samples.synchronize do
      @samples[label] ||= { :count => 0, :max => 0, :min => nil, :sum => 0, :average => 0 }
      @samples[label][:count] += 1
      @samples[label][:sum] += duration
      @samples[label][:max] = [ @samples[label][:max], duration ].max
      @samples[label][:min] = [ @samples[label][:min], duration ].reject { |val| val.nil? }.min
      @samples[label][:average] = @samples[label][:sum] / @samples[label][:count]
    end
  end

  def data
    samples.synchronize do
      @samples.dup
    end
  end
end

Version data entries

57 entries across 57 versions & 3 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/util/instrumentation/listeners/performance.rb
puppet-parse-0.1.3 lib/vendor/puppet/util/instrumentation/listeners/performance.rb
puppet-parse-0.1.2 lib/vendor/puppet/util/instrumentation/listeners/performance.rb
puppet-parse-0.1.1 lib/vendor/puppet/util/instrumentation/listeners/performance.rb
puppet-2.7.26 lib/puppet/util/instrumentation/listeners/performance.rb
puppet-2.7.25 lib/puppet/util/instrumentation/listeners/performance.rb
puppet-2.7.24 lib/puppet/util/instrumentation/listeners/performance.rb
puppet-3.3.2 lib/puppet/util/instrumentation/listeners/performance.rb
puppet-3.3.1 lib/puppet/util/instrumentation/listeners/performance.rb
puppet-3.3.1.rc3 lib/puppet/util/instrumentation/listeners/performance.rb
puppet-3.3.1.rc2 lib/puppet/util/instrumentation/listeners/performance.rb
puppet-3.3.1.rc1 lib/puppet/util/instrumentation/listeners/performance.rb
puppet-3.3.0 lib/puppet/util/instrumentation/listeners/performance.rb
puppet-3.3.0.rc3 lib/puppet/util/instrumentation/listeners/performance.rb
puppet-3.3.0.rc2 lib/puppet/util/instrumentation/listeners/performance.rb
puppet-3.2.4 lib/puppet/util/instrumentation/listeners/performance.rb
puppet-2.7.23 lib/puppet/util/instrumentation/listeners/performance.rb
puppet-3.2.3 lib/puppet/util/instrumentation/listeners/performance.rb
puppet-3.2.3.rc1 lib/puppet/util/instrumentation/listeners/performance.rb
puppet-3.2.2 lib/puppet/util/instrumentation/listeners/performance.rb