Class: Profiler::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/profiler/profile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProfile

Returns a new instance of Profile.



5
6
7
8
9
10
# 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

Instance Attribute Details

#paths_countsObject

Returns the value of attribute paths_counts.



3
4
5
# File 'lib/profiler/profile.rb', line 3

def paths_counts
  @paths_counts
end

#paths_durationsObject

Returns the value of attribute paths_durations.



3
4
5
# File 'lib/profiler/profile.rb', line 3

def paths_durations
  @paths_durations
end

#previous_lineObject

Returns the value of attribute previous_line.



3
4
5
# File 'lib/profiler/profile.rb', line 3

def previous_line
  @previous_line
end

#previous_timeObject

Returns the value of attribute previous_time.



3
4
5
# File 'lib/profiler/profile.rb', line 3

def previous_time
  @previous_time
end

Instance Method Details

#check(caller_offset = 0) ⇒ Object



12
13
14
15
16
17
18
19
20
# 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

#stopObject



22
23
24
25
26
# File 'lib/profiler/profile.rb', line 22

def stop
  result = Result.new(self)
  FlatPrinter.new(result).print
  result
end