module OneApm::Agent::BusyCalculator

Attributes

accumulator[R]
harvest_start[R]

Public Instance Methods

busy_count() click to toggle source
# File lib/one_apm/agent/busy_calculator.rb, line 41
def busy_count
  @entrypoint_stack.size
end
dispatcher_finish(end_time = nil) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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

Private Instance Methods

time_now() click to toggle source
# File lib/one_apm/agent/busy_calculator.rb, line 82
def time_now
  Time.now
end