Class: TestProf::TPSProf::Profiler
- Inherits:
-
Object
- Object
- TestProf::TPSProf::Profiler
- Defined in:
- lib/test_prof/tps_prof/profiler.rb
Instance Attribute Summary collapse
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
-
#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(top_count, threshold: 10) ⇒ Profiler
constructor
A new instance of Profiler.
Constructor Details
#initialize(top_count, threshold: 10) ⇒ Profiler
Returns a new instance of Profiler.
10 11 12 13 14 15 16 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 10 def initialize(top_count, threshold: 10) @threshold = threshold @top_count = top_count @total_count = 0 @total_time = 0.0 @groups = Utils::SizedOrderedSet.new(top_count, sort_by: :tps) end |
Instance Attribute Details
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
8 9 10 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 8 def groups @groups end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
8 9 10 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 8 def threshold @threshold end |
#top_count ⇒ Object (readonly)
Returns the value of attribute top_count.
8 9 10 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 8 def top_count @top_count end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
8 9 10 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 8 def total_count @total_count end |
#total_time ⇒ Object (readonly)
Returns the value of attribute total_time.
8 9 10 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 8 def total_time @total_time end |
Instance Method Details
#example_finished(id) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 45 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
41 42 43 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 41 def example_started(id) @example_started_at = TestProf.now end |
#group_finished(id) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/test_prof/tps_prof/profiler.rb', line 25 def group_finished(id) return unless @examples_count >= threshold # Context-time group_time = (TestProf.now - @group_started_at) - @examples_time run_time = @examples_time + group_time groups << { id: id, run_time: run_time, group_time: group_time, count: @examples_count, tps: -(@examples_count / run_time).round(2) } end |