Module: OneApm::Agent::BusyCalculator
- Extended by:
- BusyCalculator
- Included in:
- BusyCalculator
- Defined in:
- lib/one_apm/agent/busy_calculator.rb
Instance Attribute Summary collapse
-
#accumulator ⇒ Object
readonly
Returns the value of attribute accumulator.
-
#harvest_start ⇒ Object
readonly
Returns the value of attribute harvest_start.
Instance Method Summary collapse
- #busy_count ⇒ Object
- #dispatcher_finish(end_time = nil) ⇒ Object
- #dispatcher_start(time) ⇒ Object
- #harvest_busy ⇒ Object
- #reset ⇒ Object
Instance Attribute Details
#accumulator ⇒ Object (readonly)
Returns the value of attribute accumulator.
11 12 13 |
# File 'lib/one_apm/agent/busy_calculator.rb', line 11 def accumulator @accumulator end |
#harvest_start ⇒ Object (readonly)
Returns the value of attribute harvest_start.
11 12 13 |
# File 'lib/one_apm/agent/busy_calculator.rb', line 11 def harvest_start @harvest_start end |
Instance Method Details
#busy_count ⇒ Object
41 42 43 |
# File 'lib/one_apm/agent/busy_calculator.rb', line 41 def busy_count @entrypoint_stack.size end |
#dispatcher_finish(end_time = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/one_apm/agent/busy_calculator.rb', line 23 def dispatcher_finish(end_time = nil) state = TransactionState.tl_get return unless state.busy_entries end_time ||= time_now callers = state.busy_entries -= 1 return if callers > 0 @lock.synchronize do if @entrypoint_stack.empty? OneApm::Manager.logger.warn("Stack underflow tracking dispatcher entry and exit!\n #{caller.join(" \n")}") else @accumulator += (end_time - @entrypoint_stack.pop).to_f end end end |
#dispatcher_start(time) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/one_apm/agent/busy_calculator.rb', line 13 def dispatcher_start(time) state = TransactionState.tl_get state.busy_entries ||= 0 callers = state.busy_entries += 1 return if callers > 1 @lock.synchronize do @entrypoint_stack.push time end end |
#harvest_busy ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/one_apm/agent/busy_calculator.rb', line 53 def harvest_busy busy = 0 t0 = time_now @lock.synchronize do busy = accumulator @accumulator = 0 @entrypoint_stack.size.times do |frame| busy += (t0 - @entrypoint_stack[frame]).to_f @entrypoint_stack[frame] = t0 end end busy = 0.0 if busy < 0.0 time_window = (t0 - harvest_start).to_f time_window = 1.0 if time_window == 0.0 busy = busy / time_window if OneApm::Manager.config[:report_instance_busy] OneApm::Manager.record_metric('Instance/Busy', busy) end @harvest_start = t0 end |
#reset ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/one_apm/agent/busy_calculator.rb', line 45 def reset @entrypoint_stack = [] TransactionState.tl_get.busy_entries = 0 @lock ||= Mutex.new @accumulator = 0 @harvest_start = time_now end |