Class: Profiler::Profile
- Inherits:
-
Object
- Object
- Profiler::Profile
- Defined in:
- lib/profiler/profile.rb
Instance Attribute Summary collapse
-
#paths_counts ⇒ Object
Returns the value of attribute paths_counts.
-
#paths_durations ⇒ Object
Returns the value of attribute paths_durations.
-
#previous_line ⇒ Object
Returns the value of attribute previous_line.
-
#previous_time ⇒ Object
Returns the value of attribute previous_time.
Instance Method Summary collapse
- #check(caller_offset = 0) ⇒ Object
-
#initialize ⇒ Profile
constructor
A new instance of Profile.
- #stop ⇒ Object
Constructor Details
#initialize ⇒ Profile
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_counts ⇒ Object
Returns the value of attribute paths_counts.
3 4 5 |
# File 'lib/profiler/profile.rb', line 3 def paths_counts @paths_counts end |
#paths_durations ⇒ Object
Returns the value of attribute paths_durations.
3 4 5 |
# File 'lib/profiler/profile.rb', line 3 def paths_durations @paths_durations end |
#previous_line ⇒ Object
Returns the value of attribute previous_line.
3 4 5 |
# File 'lib/profiler/profile.rb', line 3 def previous_line @previous_line end |
#previous_time ⇒ Object
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 |
#stop ⇒ Object
22 23 24 25 26 |
# File 'lib/profiler/profile.rb', line 22 def stop result = Result.new(self) FlatPrinter.new(result).print result end |