class Profiler::Profile

Attributes

paths_counts[RW]
paths_durations[RW]
previous_line[RW]
previous_time[RW]
result[RW]

Public Class Methods

new() click to toggle source
# File lib/profiler/profile.rb, line 5
def initialize
  self.paths_counts = Hash.new(0)
  self.paths_durations = Hash.new(0)
  self.previous_line = nil
  self.previous_time = Time.now.to_f
end

Public Instance Methods

check(caller_offset=0) click to toggle source
# File lib/profiler/profile.rb, line 12
def check(caller_offset=0)
  now = Time.now.to_f
  line = caller[caller_offset + 1].split("/")[-1]
  path = "#{self.previous_line} -> #{line}"
  self.paths_counts[path] += 1
  self.paths_durations[path] += now - self.previous_time
  self.previous_line = line.freeze
  self.previous_time = now
end
print() click to toggle source
stop() click to toggle source
# File lib/profiler/profile.rb, line 22
def stop
  self.result = Result.new(self)
  print
  nil
end