class Puppet::Util::Profiler::AroundProfiler

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

Public Instance Methods

add_profiler(profiler) click to toggle source

@param profiler [profile] A profiler for the current thread @api private

# File lib/puppet/util/profiler/around_profiler.rb, line 28
def add_profiler(profiler)
  @profilers << profiler
  profiler
end
clear() click to toggle source

Reset the profiling system to the original state

@api private

# File lib/puppet/util/profiler/around_profiler.rb, line 15
def clear
  @profilers = []
end
current() click to toggle source

Retrieve the current list of profilers

@api private

# File lib/puppet/util/profiler/around_profiler.rb, line 22
def current
  @profilers
end
profile(message, metric_id = nil) { || ... } click to toggle source

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

# File lib/puppet/util/profiler/around_profiler.rb, line 50
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
remove_profiler(profiler) click to toggle source

@param profiler [profile] A profiler to remove from the current thread @api private

# File lib/puppet/util/profiler/around_profiler.rb, line 35
def remove_profiler(profiler)
  @profilers.delete(profiler)
end

Public Class Methods

new() click to toggle source
# File lib/puppet/util/profiler/around_profiler.rb, line 8
def initialize
  @profilers = []
end