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 Class Methods
# File lib/puppet/util/profiler/around_profiler.rb 9 def initialize 10 @profilers = [] 11 end
Public Instance Methods
@param profiler [#profile] A profiler for the current thread @api private
# File lib/puppet/util/profiler/around_profiler.rb 29 def add_profiler(profiler) 30 @profilers << profiler 31 profiler 32 end
Reset the profiling system to the original state
@api private
# File lib/puppet/util/profiler/around_profiler.rb 16 def clear 17 @profilers = [] 18 end
Retrieve the current list of profilers
@api private
# File lib/puppet/util/profiler/around_profiler.rb 23 def current 24 @profilers 25 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 hierarchy.
@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 51 def profile(message, metric_id) 52 retval = nil 53 contexts = {} 54 @profilers.each do |profiler| 55 contexts[profiler] = profiler.start(message, metric_id) 56 end 57 58 begin 59 retval = yield 60 ensure 61 @profilers.each do |profiler| 62 profiler.finish(contexts[profiler], message, metric_id) 63 end 64 end 65 66 retval 67 end
@param profiler [#profile] A profiler to remove from the current thread @api private
# File lib/puppet/util/profiler/around_profiler.rb 36 def remove_profiler(profiler) 37 @profilers.delete(profiler) 38 end