Class: Puppet::Util::Profiler::AroundProfiler Private
- Defined in:
- lib/puppet/util/profiler/around_profiler.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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.
Instance Method Summary collapse
- #add_profiler(profiler) ⇒ Object private
-
#clear ⇒ Object
private
Reset the profiling system to the original state.
-
#current ⇒ Object
private
Retrieve the current list of profilers.
-
#initialize ⇒ AroundProfiler
constructor
private
A new instance of AroundProfiler.
-
#profile(message, metric_id) ⇒ Object
private
Profile a block of code and log the time it took to execute.
- #remove_profiler(profiler) ⇒ Object private
Constructor Details
#initialize ⇒ AroundProfiler
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of AroundProfiler.
9 10 11 |
# File 'lib/puppet/util/profiler/around_profiler.rb', line 9 def initialize @profilers = [] end |
Instance Method Details
#add_profiler(profiler) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 30 31 32 |
# File 'lib/puppet/util/profiler/around_profiler.rb', line 29 def add_profiler(profiler) @profilers << profiler profiler end |
#clear ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reset the profiling system to the original state
16 17 18 |
# File 'lib/puppet/util/profiler/around_profiler.rb', line 16 def clear @profilers = [] end |
#current ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Retrieve the current list of profilers
23 24 25 |
# File 'lib/puppet/util/profiler/around_profiler.rb', line 23 def current @profilers end |
#profile(message, metric_id) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/puppet/util/profiler/around_profiler.rb', line 51 def profile(, metric_id) retval = nil contexts = {} @profilers.each do |profiler| contexts[profiler] = profiler.start(, metric_id) end begin retval = yield ensure @profilers.each do |profiler| profiler.finish(contexts[profiler], , metric_id) end end retval end |
#remove_profiler(profiler) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 |
# File 'lib/puppet/util/profiler/around_profiler.rb', line 36 def remove_profiler(profiler) @profilers.delete(profiler) end |