Sha256: a97994e3088d313cc192bf316cfe5f6e841d2a240309503241f108de0168710a
Contents?: true
Size: 1.35 KB
Versions: 4
Compression:
Stored size: 1.35 KB
Contents
# encoding: utf-8 require 'metriks' require 'singleton' class GCStats include Singleton # RUBY 1.9.X-Implementation module Yarv def enable GC::Profiler.enable end def clear GC::Profiler.clear end def gather count_collections count_allocations count_objects Metriks.timer('gc_stats.total_time').update(GC::Profiler.total_time) end def count_collections Metriks.histogram('gc_stats.collections').update(GC.count) end def count_allocations allocated_size = GC.respond_to?(:malloc_allocated_size) ? GC.malloc_allocated_size / 1000.0 : 0 Metriks.histogram('gc_stats.allocated').update(allocated_size) end def count_objects objects = ObjectSpace.count_objects objects = objects[:TOTAL] - objects[:FREE] Metriks.histogram('gc_stats.objects').update(objects) end end if RUBY_VERSION =~ /^1\.9/ extend Yarv end def self.available? respond_to?(:gather) end def self.start! if available? enable $log.info("gc:stats", enabled: true) EventMachine.next_tick do EventMachine::PeriodicTimer.new(60*60) do GC.start end EventMachine::PeriodicTimer.new(60) do gather clear end end else $log.info("gc:stats", enabled: false) end end end
Version data entries
4 entries across 4 versions & 1 rubygems