Class: Timmy::TargetedTimer
- Inherits:
-
Object
- Object
- Timmy::TargetedTimer
- Defined in:
- lib/timmy/targeted_timer.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Class Method Summary collapse
- .put_stopped_profiles ⇒ Object
- .start_for_line(line) ⇒ Object
- .started ⇒ Object
- .stop(timer) ⇒ Object
- .stop_all ⇒ Object
- .stop_by_id(id) ⇒ Object
- .stop_for_line(line) ⇒ Object
- .stopped ⇒ Object
Instance Method Summary collapse
-
#initialize(definition, label: nil) ⇒ TargetedTimer
constructor
A new instance of TargetedTimer.
- #put_profile ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(definition, label: nil) ⇒ TargetedTimer
Returns a new instance of TargetedTimer.
56 57 58 59 60 |
# File 'lib/timmy/targeted_timer.rb', line 56 def initialize(definition, label: nil) @definition = definition @start_time = MasterTimer.get @label = label end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
54 55 56 |
# File 'lib/timmy/targeted_timer.rb', line 54 def definition @definition end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
54 55 56 |
# File 'lib/timmy/targeted_timer.rb', line 54 def duration @duration end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
54 55 56 |
# File 'lib/timmy/targeted_timer.rb', line 54 def label @label end |
Class Method Details
.put_stopped_profiles ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/timmy/targeted_timer.rb', line 45 def put_stopped_profiles puts "" puts "Slowest targeted timers:" TargetedTimer.stopped.sort_by { |timer| -timer.duration }[0..9].each do |timer| timer.put_profile end end |
.start_for_line(line) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/timmy/targeted_timer.rb', line 4 def start_for_line(line) TargetedTimerDefinition.all.each do |definition| if match = line.match(definition.start_regex) stop_by_id(definition.id) label = match.send(:[], :label) rescue nil started.push(self.new(definition, label: label)) end end end |
.started ⇒ Object
37 38 39 |
# File 'lib/timmy/targeted_timer.rb', line 37 def started @started ||= [] end |
.stop(timer) ⇒ Object
22 23 24 25 26 |
# File 'lib/timmy/targeted_timer.rb', line 22 def stop(timer) timer.stop started.delete(timer) stopped.push(timer) end |
.stop_all ⇒ Object
33 34 35 |
# File 'lib/timmy/targeted_timer.rb', line 33 def stop_all started.each { |timer| stop(timer) } end |
.stop_by_id(id) ⇒ Object
28 29 30 31 |
# File 'lib/timmy/targeted_timer.rb', line 28 def stop_by_id(id) matches = started.select { |timer| timer.definition.id == id } matches.each { |timer| stop(timer) } end |
.stop_for_line(line) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/timmy/targeted_timer.rb', line 14 def stop_for_line(line) started.each do |timer| if (stop_regex = timer.definition.stop_regex) && line.match?(stop_regex) stop(timer) end end end |
.stopped ⇒ Object
41 42 43 |
# File 'lib/timmy/targeted_timer.rb', line 41 def stopped @stopped ||= [] end |
Instance Method Details
#put_profile ⇒ Object
67 68 69 70 |
# File 'lib/timmy/targeted_timer.rb', line 67 def put_profile duration = Logger.format_duration(@duration) puts " - #{duration} - #{formatted_id} - #{@label}" end |
#stop ⇒ Object
62 63 64 65 |
# File 'lib/timmy/targeted_timer.rb', line 62 def stop put @duration = MasterTimer.get - @start_time end |