class TimeBandits::TimeConsumers::GarbageCollection

Constants

GCFORMAT

Public Class Methods

heap_dumps_enabled=(v) click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 6
def self.heap_dumps_enabled=(v)
  @@heap_dumps_enabled = v
end
instance() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 16
def self.instance
  @instance ||= new
end
new() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 10
def initialize
  enable_stats
  reset
end

Public Instance Methods

_get_allocated_objects() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 38
def _get_allocated_objects; GC.stat(:total_allocated_objects); end
_get_allocated_size() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 41
def _get_allocated_size; GC.total_malloced_bytes; end
_get_collections() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 36
def _get_collections; GC.count; end
_get_gc_time() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 31
def _get_gc_time; GC.time; end
_get_heap_slots() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 47
def _get_heap_slots; GC.heap_slots; end
allocated_objects() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 79
def allocated_objects
  _get_allocated_objects - @allocated_objects
end
allocated_size() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 83
def allocated_size
  _get_allocated_size - @allocated_size
end
collections() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 75
def collections
  _get_collections - @collections
end
consumed() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 66
def consumed
  0.0
end
Also aliased as: current_runtime
consumed_gc_time() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 71
def consumed_gc_time # ms
  (_get_gc_time - @consumed).to_f / 1000
end
current_runtime()
Alias for: consumed
enable_stats() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 20
def enable_stats
  return unless GC.respond_to? :enable_stats
  GC.enable_stats
  if defined?(PhusionPassenger)
    PhusionPassenger.on_event(:starting_worker_process) do |forked|
      GC.enable_stats if forked
    end
  end
end
heap_growth() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 87
def heap_growth
  _get_heap_slots - @heap_slots
end
live_data_set_size() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 53
def live_data_set_size; GC.heap_slots_live_after_last_gc; end
metrics() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 102
def metrics
  {
    :gc_time => consumed_gc_time,
    :gc_calls => collections,
    :heap_growth => heap_growth,
    :heap_size => _get_heap_slots,
    :allocated_objects => allocated_objects,
    :allocated_bytes => allocated_size,
    :live_data_set_size => live_data_set_size
  }
end
reset() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 58
def reset
  @consumed = _get_gc_time
  @collections = _get_collections
  @allocated_objects = _get_allocated_objects
  @allocated_size = _get_allocated_size
  @heap_slots = _get_heap_slots
end
runtime() click to toggle source
# File lib/time_bandits/time_consumers/garbage_collection.rb, line 93
def runtime
  heap_slots = _get_heap_slots
  heap_growth = self.heap_growth
  allocated_objects = self.allocated_objects
  allocated_size = self.allocated_size
  GCHacks.heap_dump if heap_growth > 0 && @@heap_dumps_enabled && defined?(GCHacks)
  GCFORMAT % [consumed_gc_time, collections, heap_growth, heap_slots, allocated_objects, allocated_size, live_data_set_size]
end