class Skylight::Core::GC

@api private

Constants

MAX_COUNT
MAX_TIME
METHODS
TH_KEY

Attributes

config[R]

Public Class Methods

new(config, profiler) click to toggle source
# File lib/skylight/core/gc.rb, line 13
def initialize(config, profiler)
  @listeners = []
  @config    = config
  @lock      = Mutex.new
  @time      = 0

  if METHODS.all? { |m| profiler.respond_to?(m) }
    @profiler = profiler
    @time = @profiler.total_time
  else
    debug "disabling GC profiling"
  end
end

Public Instance Methods

enable() click to toggle source
# File lib/skylight/core/gc.rb, line 27
def enable
  @profiler.enable if @profiler
end
release(win) click to toggle source
# File lib/skylight/core/gc.rb, line 58
def release(win)
  @lock.synchronize do
    @listeners.delete(win)
  end
end
total_time() click to toggle source

Total time in microseconds for GC over entire process lifetime

# File lib/skylight/core/gc.rb, line 32
def total_time
  @profiler ? @profiler.total_time : nil
end
track() click to toggle source
# File lib/skylight/core/gc.rb, line 36
def track
  if @profiler
    win = Window.new(self)

    @lock.synchronize do
      __update
      @listeners << win

      # Cleanup any listeners that might have leaked
      @listeners.shift until @listeners[0].time < MAX_TIME

      if @listeners.length > MAX_COUNT
        @listeners.shift
      end
    end

    win
  else
    Window.new(nil)
  end
end
update() click to toggle source
# File lib/skylight/core/gc.rb, line 64
def update
  @lock.synchronize do
    __update
  end

  nil
end

Private Instance Methods

__update() click to toggle source
# File lib/skylight/core/gc.rb, line 74
def __update
  time  = @profiler.total_time
  diff  = time - @time
  @time = time

  if diff > 0
    @listeners.each do |l|
      l.add(diff)
    end
  end
end