Sha256: ce645554b5b34391837730e3c30e6cd6a1ac98198e6f8c1161d80f3a2db47ceb

Contents?: true

Size: 1.7 KB

Versions: 50

Compression:

Stored size: 1.7 KB

Contents

# A Profiler that can be used to wrap around blocks of code. It is configured
# with other profilers and controls them to start before the block is executed
# and finish after the block is executed.
#
# @api private
class Puppet::Util::Profiler::AroundProfiler

  def initialize
    @profilers = []
  end

  # Reset the profiling system to the original state
  #
  # @api private
  def clear
    @profilers = []
  end

  # Retrieve the current list of profilers
  #
  # @api private
  def current
    @profilers
  end

  # @param profiler [#profile] A profiler for the current thread
  # @api private
  def add_profiler(profiler)
    @profilers << profiler
    profiler
  end

  # @param profiler [#profile] A profiler to remove from the current thread
  # @api private
  def remove_profiler(profiler)
    @profilers.delete(profiler)
  end

  # Profile a block of code and log the time it took to execute.
  #
  # This outputs logs entries to the Puppet masters logging destination
  # providing the time it took, a message describing the profiled code
  # and a leaf location marking where the profile method was called
  # in the profiled hierachy.
  #
  # @param message [String] A description of the profiled event
  # @param metric_id [Array] A list of strings making up the ID of a metric to profile
  # @param block [Block] The segment of code to profile
  # @api private
  def profile(message, metric_id = nil)
    retval = nil
    contexts = {}
    @profilers.each do |profiler|
      contexts[profiler] = profiler.start(message, metric_id)
    end

    begin
      retval = yield
    ensure
      @profilers.each do |profiler|
        profiler.finish(contexts[profiler], message, metric_id)
      end
    end

    retval
  end
end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
puppet-retrospec-0.12.2 vendor/gems/puppet-3.7.3/lib/puppet/util/profiler/around_profiler.rb
puppet-3.8.7 lib/puppet/util/profiler/around_profiler.rb
puppet-3.8.7-x86-mingw32 lib/puppet/util/profiler/around_profiler.rb
puppet-3.8.7-x64-mingw32 lib/puppet/util/profiler/around_profiler.rb
puppet-3.8.6 lib/puppet/util/profiler/around_profiler.rb
puppet-3.8.6-x86-mingw32 lib/puppet/util/profiler/around_profiler.rb
puppet-retrospec-0.12.1 vendor/gems/puppet-3.7.3/lib/puppet/util/profiler/around_profiler.rb
puppet-3.8.6-x64-mingw32 lib/puppet/util/profiler/around_profiler.rb
puppet-retrospec-0.12.0 vendor/gems/puppet-3.7.3/lib/puppet/util/profiler/around_profiler.rb
puppet-3.8.5 lib/puppet/util/profiler/around_profiler.rb
puppet-3.8.5-x86-mingw32 lib/puppet/util/profiler/around_profiler.rb
puppet-3.8.5-x64-mingw32 lib/puppet/util/profiler/around_profiler.rb
puppet-3.8.4 lib/puppet/util/profiler/around_profiler.rb
puppet-3.8.4-x86-mingw32 lib/puppet/util/profiler/around_profiler.rb
puppet-3.8.4-x64-mingw32 lib/puppet/util/profiler/around_profiler.rb
puppet-retrospec-0.11.0 vendor/gems/puppet-3.7.3/lib/puppet/util/profiler/around_profiler.rb
puppet-retrospec-0.10.0 vendor/gems/puppet-3.7.3/lib/puppet/util/profiler/around_profiler.rb
puppet-retrospec-0.9.1 vendor/gems/puppet-3.7.3/lib/puppet/util/profiler/around_profiler.rb
puppet-retrospec-0.9.0 vendor/gems/puppet-3.7.3/lib/puppet/util/profiler/around_profiler.rb
puppet-retrospec-0.8.1 vendor/gems/puppet-3.7.3/lib/puppet/util/profiler/around_profiler.rb