Class: Puppet::Util::Profiler::Logging

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/util/profiler/logging.rb

Direct Known Subclasses

ObjectCounts, WallClock

Defined Under Namespace

Classes: Sequence

Instance Method Summary collapse

Constructor Details

#initialize(logger, identifier) ⇒ Logging

Returns a new instance of Logging.



2
3
4
5
6
# File 'lib/puppet/util/profiler/logging.rb', line 2

def initialize(logger, identifier)
  @logger = logger
  @identifier = identifier
  @sequence = Sequence.new
end

Instance Method Details

#profile(description, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/puppet/util/profiler/logging.rb', line 8

def profile(description, &block)
  retval = nil
  @sequence.next
  @sequence.down
  context = start
  begin
    retval = yield
  ensure
    profile_explanation = finish(context)
    @sequence.up
    @logger.call("PROFILE [#{@identifier}] #{@sequence} #{description}: #{profile_explanation}")
  end
  retval
end