class Profiler::Entry
Attributes
duration[R]
Public Class Methods
new(format)
click to toggle source
# File lib/log_and_profile.rb, line 62 def initialize(format) @format = format @start = Time.now end
Public Instance Methods
add_child(child)
click to toggle source
# File lib/log_and_profile.rb, line 84 def add_child(child) @children ||= [] @children << child end
dump(level = 0)
click to toggle source
# File lib/log_and_profile.rb, line 97 def dump(level = 0) self.finished! STDERR.puts indent(level) + (@format % @duration) if @groups @groups.sort_by { |group, info| info[:duration] }.reverse_each do |group, info| STDERR.puts indent(level+1) + "[#{group}: %.3f seconds, called #{info[:count]} time(s), %.3f seconds/time]" % [ info[:duration], info[:duration] / info[:count] ] end end if @children @children.sort_by { |child| child.duration }.reverse_each do |child| child.dump(level + 1) end end end
finished!()
click to toggle source
# File lib/log_and_profile.rb, line 89 def finished! @duration ||= Time.now - @start end
group(name) { || ... }
click to toggle source
# File lib/log_and_profile.rb, line 67 def group(name) @groups ||= {} @groups[name] ||= { :duration => 0, :count => 0 } previous_group, @current_group = @current_group, name start = Time.now res = yield @groups[name][:duration] += Time.now - start @groups[name][:count] += 1 @groups[previous_group][:duration] -= Time.now - start if previous_group @current_group = previous_group res end
indent(level)
click to toggle source
# File lib/log_and_profile.rb, line 93 def indent(level) ' ' * level end