class Profiler

Public Class Methods

enabled() click to toggle source
# File lib/log_and_profile.rb, line 20
def self.enabled
  @@instance ? true : false
end
enabled=(flag) click to toggle source
# File lib/log_and_profile.rb, line 15
def self.enabled=(flag)
  @@instance.dump if @@instance
  @@instance = flag ? Profiler.new : nil
end
group(group, &block) click to toggle source
# File lib/log_and_profile.rb, line 32
def self.group(group, &block)
  if @@instance
    @@instance.profile_group(group, &block)
  else
    block.call
  end
end
new(format = "Program ran in %.3f seconds") click to toggle source
# File lib/log_and_profile.rb, line 11
def initialize(format = "Program ran in %.3f seconds")
  @current = Entry.new(format)
end
run(action, &block) click to toggle source
# File lib/log_and_profile.rb, line 24
def self.run(action, &block)
  if @@instance
    @@instance.profile("#{action} took %.3f seconds", &block)
  else
    block.call
  end
end

Public Instance Methods

dump() click to toggle source
# File lib/log_and_profile.rb, line 55
def dump
  @current.dump
end
profile(format) { || ... } click to toggle source
# File lib/log_and_profile.rb, line 40
def profile(format)
  parent = @current
  parent.add_child(@current = Entry.new(format))
  res = yield
  @current.finished!
  @current = parent
  res
end
profile_group(group) { || ... } click to toggle source
# File lib/log_and_profile.rb, line 49
def profile_group(group)
  @current.group(group) do
    yield
  end
end