Class: TestProf::EventProf::Profiler
- Inherits:
-
Object
- Object
- TestProf::EventProf::Profiler
show all
- Includes:
- Logging
- Defined in:
- lib/test_prof/event_prof.rb
Overview
Constant Summary
Constants included
from Logging
Logging::COLORS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logging
#build_log_msg, #colorize, #log
Constructor Details
#initialize(event:, instrumenter:) ⇒ Profiler
Returns a new instance of Profiler.
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/test_prof/event_prof.rb', line 89
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
Returns the value of attribute event.
87
88
89
|
# File 'lib/test_prof/event_prof.rb', line 87
def event
@event
end
|
#total_count ⇒ Object
Returns the value of attribute total_count.
87
88
89
|
# File 'lib/test_prof/event_prof.rb', line 87
def total_count
@total_count
end
|
#total_time ⇒ Object
Returns the value of attribute total_time.
87
88
89
|
# File 'lib/test_prof/event_prof.rb', line 87
def total_time
@total_time
end
|
Instance Method Details
#example_finished(id) ⇒ Object
141
142
143
144
145
146
147
148
|
# File 'lib/test_prof/event_prof.rb', line 141
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
135
136
137
138
139
|
# File 'lib/test_prof/event_prof.rb', line 135
def example_started(id)
return unless config.per_example?
reset_example!
@current_example = id
end
|
#group_finished(id) ⇒ Object
127
128
129
130
131
132
133
|
# File 'lib/test_prof/event_prof.rb', line 127
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
122
123
124
125
|
# File 'lib/test_prof/event_prof.rb', line 122
def group_started(id)
reset_group!
@current_group = id
end
|
#rank_by ⇒ Object
160
161
162
|
# File 'lib/test_prof/event_prof.rb', line 160
def rank_by
EventProf.config.rank_by
end
|
#results ⇒ Object
150
151
152
153
154
155
156
157
158
|
# File 'lib/test_prof/event_prof.rb', line 150
def results
{
groups: @groups.to_a
}.tap do |data|
next unless config.per_example?
data[:examples] = @examples.to_a
end
end
|
#top_count ⇒ Object
164
165
166
|
# File 'lib/test_prof/event_prof.rb', line 164
def top_count
EventProf.config.top_count
end
|
#track(time) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/test_prof/event_prof.rb', line 108
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
|