Class: TestProf::TPSProf::Profiler

Inherits:
Object
  • Object
show all
Defined in:
lib/test_prof/tps_prof/profiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#groupsObject (readonly)

Returns the value of attribute groups.



8
9
10
# File 'lib/test_prof/tps_prof/profiler.rb', line 8

def groups
  @groups
end

#thresholdObject (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_countObject (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_countObject (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_timeObject (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

#group_started(id) ⇒ Object



18
19
20
21
22
23
# File 'lib/test_prof/tps_prof/profiler.rb', line 18

def group_started(id)
  @current_group = id
  @examples_count = 0
  @examples_time = 0.0
  @group_started_at = TestProf.now
end