Class: Results

Inherits:
Object
  • Object
show all
Defined in:
lib/sparkle_motion/results.rb

Overview

Helper class to hold onto stats about requests made to the bridges.

NOTE: Methods ending with ‘!` are not thread-safe, methods without it are.

TODO: Track things by light index, bridge, etc…

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger:) ⇒ Results

Returns a new instance of Results.



12
13
14
15
16
# File 'lib/sparkle_motion/results.rb', line 12

def initialize(logger:)
  @logger = logger
  @mutex  = Mutex.new
  clear!
end

Instance Attribute Details

#end_timeObject (readonly)

Returns the value of attribute end_time.



9
10
11
# File 'lib/sparkle_motion/results.rb', line 9

def end_time
  @end_time
end

#failuresObject (readonly)

Returns the value of attribute failures.



9
10
11
# File 'lib/sparkle_motion/results.rb', line 9

def failures
  @failures
end

#hard_timeoutsObject (readonly)

Returns the value of attribute hard_timeouts.



9
10
11
# File 'lib/sparkle_motion/results.rb', line 9

def hard_timeouts
  @hard_timeouts
end

#soft_timeoutsObject (readonly)

Returns the value of attribute soft_timeouts.



9
10
11
# File 'lib/sparkle_motion/results.rb', line 9

def soft_timeouts
  @soft_timeouts
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



9
10
11
# File 'lib/sparkle_motion/results.rb', line 9

def start_time
  @start_time
end

#successesObject (readonly)

Returns the value of attribute successes.



9
10
11
# File 'lib/sparkle_motion/results.rb', line 9

def successes
  @successes
end

Instance Method Details

#add_from(other) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/sparkle_motion/results.rb', line 63

def add_from(other)
  @mutex.synchronize do
    @successes      += other.successes
    @failures       += other.failures
    @hard_timeouts  += other.hard_timeouts
    @soft_timeouts  += other.soft_timeouts
  end
end

#all_failuresObject



53
# File 'lib/sparkle_motion/results.rb', line 53

def all_failures; @failures + @hard_timeouts + @soft_timeouts; end

#begin!Object



25
# File 'lib/sparkle_motion/results.rb', line 25

def begin!; @start_time ||= Time.now.to_f; end

#clear!Object



18
19
20
21
22
23
# File 'lib/sparkle_motion/results.rb', line 18

def clear!
  @successes      = 0
  @failures       = 0
  @hard_timeouts  = 0
  @soft_timeouts  = 0
end

#done!Object



26
# File 'lib/sparkle_motion/results.rb', line 26

def done!; @end_time ||= Time.now.to_f; end

#elapsedObject



51
# File 'lib/sparkle_motion/results.rb', line 51

def elapsed; @end_time - @start_time; end

#failure!(info = nil) ⇒ Object



36
37
38
39
# File 'lib/sparkle_motion/results.rb', line 36

def failure!(info = nil)
  @logger.error { info } if info
  @failures += 1
end

#failure_rateObject



61
# File 'lib/sparkle_motion/results.rb', line 61

def failure_rate; ratio(all_failures * 100, requests); end

#failures_secObject



57
# File 'lib/sparkle_motion/results.rb', line 57

def failures_sec; ratio(failures, elapsed); end

#hard_timeout!(info = nil) ⇒ Object



41
42
43
44
# File 'lib/sparkle_motion/results.rb', line 41

def hard_timeout!(info = nil)
  @logger.error { info } if info
  @hard_timeouts += 1
end

#hard_timeouts_secObject



58
# File 'lib/sparkle_motion/results.rb', line 58

def hard_timeouts_sec; ratio(hard_timeouts, elapsed); end

#requestsObject



52
# File 'lib/sparkle_motion/results.rb', line 52

def requests; @successes + @failures + @hard_timeouts + @soft_timeouts; end

#requests_secObject



55
# File 'lib/sparkle_motion/results.rb', line 55

def requests_sec; ratio(requests, elapsed); end

#soft_timeout!(info = nil) ⇒ Object



46
47
48
49
# File 'lib/sparkle_motion/results.rb', line 46

def soft_timeout!(info = nil)
  @logger.error { info } if info
  @soft_timeouts += 1
end

#soft_timeouts_secObject



59
# File 'lib/sparkle_motion/results.rb', line 59

def soft_timeouts_sec; ratio(soft_timeouts, elapsed); end

#success!(info = nil) ⇒ Object

TODO: Colorized output for all feedback types, or running counters, or TODO: something…



31
32
33
34
# File 'lib/sparkle_motion/results.rb', line 31

def success!(info = nil)
  @logger.error { info } if info
  @successes += 1
end

#successes_secObject



56
# File 'lib/sparkle_motion/results.rb', line 56

def successes_sec; ratio(successes, elapsed); end