Class: Results
- Inherits:
-
Object
- Object
- Results
- 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
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#hard_timeouts ⇒ Object
readonly
Returns the value of attribute hard_timeouts.
-
#soft_timeouts ⇒ Object
readonly
Returns the value of attribute soft_timeouts.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#successes ⇒ Object
readonly
Returns the value of attribute successes.
Instance Method Summary collapse
- #add_from(other) ⇒ Object
- #all_failures ⇒ Object
- #begin! ⇒ Object
- #clear! ⇒ Object
- #done! ⇒ Object
- #elapsed ⇒ Object
- #failure!(info = nil) ⇒ Object
- #failure_rate ⇒ Object
- #failures_sec ⇒ Object
- #hard_timeout!(info = nil) ⇒ Object
- #hard_timeouts_sec ⇒ Object
-
#initialize(logger:) ⇒ Results
constructor
A new instance of Results.
- #requests ⇒ Object
- #requests_sec ⇒ Object
- #soft_timeout!(info = nil) ⇒ Object
- #soft_timeouts_sec ⇒ Object
-
#success!(info = nil) ⇒ Object
TODO: Colorized output for all feedback types, or running counters, or TODO: something…
- #successes_sec ⇒ Object
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_time ⇒ Object (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 |
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
9 10 11 |
# File 'lib/sparkle_motion/results.rb', line 9 def failures @failures end |
#hard_timeouts ⇒ Object (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_timeouts ⇒ Object (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_time ⇒ Object (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 |
#successes ⇒ Object (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_failures ⇒ Object
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 |
#elapsed ⇒ Object
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_rate ⇒ Object
61 |
# File 'lib/sparkle_motion/results.rb', line 61 def failure_rate; ratio(all_failures * 100, requests); end |
#failures_sec ⇒ Object
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_sec ⇒ Object
58 |
# File 'lib/sparkle_motion/results.rb', line 58 def hard_timeouts_sec; ratio(hard_timeouts, elapsed); end |
#requests ⇒ Object
52 |
# File 'lib/sparkle_motion/results.rb', line 52 def requests; @successes + @failures + @hard_timeouts + @soft_timeouts; end |
#requests_sec ⇒ Object
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_sec ⇒ Object
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_sec ⇒ Object
56 |
# File 'lib/sparkle_motion/results.rb', line 56 def successes_sec; ratio(successes, elapsed); end |