Class: TestProf::EventProf::Profiler
- Inherits:
-
Object
- Object
- TestProf::EventProf::Profiler
- Includes:
- Logging
- Defined in:
- lib/test_prof/event_prof.rb
Overview
:nodoc:
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#rank_by ⇒ Object
readonly
Returns the value of attribute rank_by.
-
#top_count ⇒ Object
readonly
Returns the value of attribute top_count.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
-
#total_time ⇒ Object
readonly
Returns the value of attribute total_time.
Instance Method Summary collapse
- #example_finished(id) ⇒ Object
- #example_started(id) ⇒ Object
- #group_finished(id) ⇒ Object
- #group_started(id) ⇒ Object
-
#initialize(event:, instrumenter:) ⇒ Profiler
constructor
A new instance of Profiler.
- #results ⇒ Object
- #track(time) ⇒ Object
Methods included from Logging
#build_log_msg, #colorize, #log
Constructor Details
#initialize(event:, instrumenter:) ⇒ Profiler
Returns a new instance of Profiler.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/test_prof/event_prof.rb', line 81 def initialize(event:, instrumenter:) @event = event log :info, "EventProf enabled (#{@event})" instrumenter.subscribe(event) { |time| track(time) } @groups = Utils::SizedOrderedSet.new( top_count, sort_by: rank_by ) @examples = Utils::SizedOrderedSet.new( top_count, sort_by: rank_by ) @total_count = 0 @total_time = 0.0 end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
79 80 81 |
# File 'lib/test_prof/event_prof.rb', line 79 def event @event end |
#rank_by ⇒ Object (readonly)
Returns the value of attribute rank_by.
79 80 81 |
# File 'lib/test_prof/event_prof.rb', line 79 def rank_by @rank_by end |
#top_count ⇒ Object (readonly)
Returns the value of attribute top_count.
79 80 81 |
# File 'lib/test_prof/event_prof.rb', line 79 def top_count @top_count end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
79 80 81 |
# File 'lib/test_prof/event_prof.rb', line 79 def total_count @total_count end |
#total_time ⇒ Object (readonly)
Returns the value of attribute total_time.
79 80 81 |
# File 'lib/test_prof/event_prof.rb', line 79 def total_time @total_time end |
Instance Method Details
#example_finished(id) ⇒ Object
133 134 135 136 137 138 139 140 |
# File 'lib/test_prof/event_prof.rb', line 133 def example_finished(id) @total_examples += 1 return unless config.per_example? data = { id: id, time: @example_time, count: @example_count } @examples << data unless data[rank_by].zero? @current_example = nil end |
#example_started(id) ⇒ Object
127 128 129 130 131 |
# File 'lib/test_prof/event_prof.rb', line 127 def example_started(id) return unless config.per_example? reset_example! @current_example = id end |
#group_finished(id) ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/test_prof/event_prof.rb', line 119 def group_finished(id) data = { id: id, time: @time, count: @count, examples: @total_examples } @groups << data unless data[rank_by].zero? @current_group = nil end |
#group_started(id) ⇒ Object
114 115 116 117 |
# File 'lib/test_prof/event_prof.rb', line 114 def group_started(id) reset_group! @current_group = id end |
#results ⇒ Object
142 143 144 145 146 147 148 149 150 |
# File 'lib/test_prof/event_prof.rb', line 142 def results { groups: @groups.to_a }.tap do |data| next unless config.per_example? data[:examples] = @examples.to_a end end |
#track(time) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/test_prof/event_prof.rb', line 100 def track(time) return if @current_group.nil? @total_time += time @total_count += 1 @time += time @count += 1 return if @current_example.nil? @example_time += time @example_count += 1 end |