Sha256: 0bed749af8d21f1dcba14d0e7a13caff15122debc92b7311f1e73961c6fe0eb2

Contents?: true

Size: 1.63 KB

Versions: 31

Compression:

Stored size: 1.63 KB

Contents

require 'benchmark'
module Puppet::Rails::Benchmark
  $benchmarks = {:accumulated => {}}

  def time_debug?
    Puppet::Rails::TIME_DEBUG
  end

  def railsmark(message)
    result = nil
    seconds = Benchmark.realtime { result = yield }
    Puppet.debug(message + " in %0.2f seconds" % seconds)

    $benchmarks[message] = seconds if time_debug?
    result
  end

  def debug_benchmark(message)
    return yield unless Puppet::Rails::TIME_DEBUG

    railsmark(message) { yield }
  end

  # Collect partial benchmarks to be logged when they're
  # all done.
  #   These are always low-level debugging so we only
  # print them if time_debug is enabled.
  def accumulate_benchmark(message, label)
    return yield unless time_debug?

    $benchmarks[:accumulated][message] ||= Hash.new(0)
    $benchmarks[:accumulated][message][label] += Benchmark.realtime { yield }
  end

  # Log the accumulated marks.
  def log_accumulated_marks(message)
    return unless time_debug?

    return if $benchmarks[:accumulated].empty? or $benchmarks[:accumulated][message].nil? or $benchmarks[:accumulated][message].empty?

    $benchmarks[:accumulated][message].each do |label, value|
      Puppet.debug(message + ("(#{label})") + (" in %0.2f seconds" % value))
    end
  end

  def write_benchmarks
    return unless time_debug?

    branch = %x{git branch}.split("\n").find { |l| l =~ /^\*/ }.sub("* ", '')

    file = "/tmp/time_debugging.yaml"

    require 'yaml'

    if FileTest.exist?(file)
      data = YAML.load_file(file)
    else
      data = {}
    end
    data[branch] = $benchmarks
    Puppet::Util.secure_open(file, "w") { |f| f.print YAML.dump(data) }
  end
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/rails/benchmark.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/rails/benchmark.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/rails/benchmark.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/rails/benchmark.rb
supply_drop-0.9.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/rails/benchmark.rb
supply_drop-0.8.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/rails/benchmark.rb
supply_drop-0.8.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/rails/benchmark.rb
supply_drop-0.7.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/rails/benchmark.rb
supply_drop-0.6.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/rails/benchmark.rb
supply_drop-0.6.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/rails/benchmark.rb
puppet-2.6.13 lib/puppet/rails/benchmark.rb
puppet-2.7.9 lib/puppet/rails/benchmark.rb
puppet-2.7.8 lib/puppet/rails/benchmark.rb
puppet-2.7.6 lib/puppet/rails/benchmark.rb
puppet-2.6.12 lib/puppet/rails/benchmark.rb
puppet-2.7.5 lib/puppet/rails/benchmark.rb
puppet-2.6.11 lib/puppet/rails/benchmark.rb
puppet-2.7.4 lib/puppet/rails/benchmark.rb
puppet-2.6.10 lib/puppet/rails/benchmark.rb
puppet-2.7.3 lib/puppet/rails/benchmark.rb