Class: Steep::Sampler
Instance Method Summary collapse
- #average ⇒ Object
- #count ⇒ Object
-
#initialize ⇒ Sampler
constructor
A new instance of Sampler.
- #percentile(p) ⇒ Object
- #sample(message) ⇒ Object
- #slowests(num) ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize ⇒ Sampler
Returns a new instance of Sampler.
251 252 253 |
# File 'lib/steep.rb', line 251 def initialize() @samples = [] end |
Instance Method Details
#average ⇒ Object
277 278 279 280 281 282 283 |
# File 'lib/steep.rb', line 277 def average if count > 0 total/count else 0.to_f end end |
#count ⇒ Object
265 266 267 |
# File 'lib/steep.rb', line 265 def count @samples.count end |
#percentile(p) ⇒ Object
285 286 287 288 |
# File 'lib/steep.rb', line 285 def percentile(p) c = [count * p / 100.to_r, 1].max or raise slowests(c.to_i).last&.last || 0.to_f end |
#sample(message) ⇒ Object
255 256 257 258 259 260 261 262 263 |
# File 'lib/steep.rb', line 255 def sample() start = Time.now begin yield ensure time = Time.now - start @samples << [, time] end end |
#slowests(num) ⇒ Object
273 274 275 |
# File 'lib/steep.rb', line 273 def slowests(num) @samples.sort_by(&:last).reverse.take(num) end |
#total ⇒ Object
269 270 271 |
# File 'lib/steep.rb', line 269 def total @samples.sum(&:last) end |