Class: TestProf::TPSProf::Profiler
- Inherits:
-
Object
- Object
- TestProf::TPSProf::Profiler
- Extended by:
- Forwardable
- Defined in:
- lib/test_prof/tps_prof/profiler.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#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(group) ⇒ Object
- #group_started(id) ⇒ Object
-
#initialize(top_count, config) ⇒ Profiler
constructor
A new instance of Profiler.
Constructor Details
#initialize(top_count, config) ⇒ Profiler
Returns a new instance of Profiler.
17 18 19 20 21 22 23 24 25 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 17 def initialize(top_count, config) @config = config # In strict mode, we use the sorted set to keep track of offenders # to show in the end @top_count = (config.mode == :strict) ? 100 : top_count @total_count = 0 @total_time = 0.0 @groups = Utils::SizedOrderedSet.new(top_count, sort_by: :penalty) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 11 def config @config end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
11 12 13 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 11 def groups @groups end |
#top_count ⇒ Object (readonly)
Returns the value of attribute top_count.
11 12 13 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 11 def top_count @top_count end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
11 12 13 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 11 def total_count @total_count end |
#total_time ⇒ Object (readonly)
Returns the value of attribute total_time.
11 12 13 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 11 def total_time @total_time end |
Instance Method Details
#example_finished(id) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 82 def example_finished(id) @examples_count += 1 @total_count += 1 time = (TestProf.now - @example_started_at) @examples_time += time @total_time += time end |
#example_started(id) ⇒ Object
78 79 80 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 78 def example_started(id) @example_started_at = TestProf.now end |
#group_finished(group) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 34 def group_finished(group) return unless @examples_count >= min_examples_count total_time = TestProf.now - @group_started_at shared_setup_time = total_time - @examples_time return unless total_time >= min_group_time tps = (@examples_count / total_time).round(2) return unless tps < min_target_tps # How much time did we waste compared to the target TPS penalty = @examples_count * ((1.0 / tps) - (1.0 / min_target_tps)) item = { id: group, total_time: total_time, shared_setup_time: shared_setup_time, count: @examples_count, tps: tps, penalty: penalty } if mode == :strict location = group.[:location] if TPSProf.handle_group_strictly( GroupInfo.new( group: group, location: location, examples_count: @examples_count, total_time: total_time, tps: tps, penalty: penalty ) ) groups << item end else groups << item end end |