Module: Puppet::Util::Profiler

Defined in:
lib/puppet/util/profiler.rb

Overview

A simple profiling callback system.

Defined Under Namespace

Classes: Logging, None, ObjectCounts, WallClock

Constant Summary collapse

NONE =
Puppet::Util::Profiler::None.new

Class Method Summary collapse

Class Method Details

.clearObject

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.rb', line 16

def self.clear
  @profiler = nil
end

.currentObject

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 This thread’s configured profiler.

Returns:

  • This thread’s configured profiler



22
23
24
# File 'lib/puppet/util/profiler.rb', line 22

def self.current
  @profiler || NONE
end

.current=(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.

Parameters:

  • profiler (#profile)

    A profiler for the current thread



28
29
30
# File 'lib/puppet/util/profiler.rb', line 28

def self.current=(profiler)
  @profiler = profiler
end

.profile(message, &block) ⇒ Object

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.

Parameters:

  • message (String)

    A description of the profiled event

  • block (Block)

    The segment of code to profile



42
43
44
# File 'lib/puppet/util/profiler.rb', line 42

def self.profile(message, &block)
  current.profile(message, &block)
end