Class: Trashed::Instruments::RubyGCProfiler

Inherits:
Object
  • Object
show all
Defined in:
lib/trashed/instruments/ruby_gc_profiler.rb

Instance Method Summary collapse

Constructor Details

#initializeRubyGCProfiler

Returns a new instance of RubyGCProfiler.



4
5
6
# File 'lib/trashed/instruments/ruby_gc_profiler.rb', line 4

def initialize
  @has_raw_data = GC::Profiler.respond_to?(:raw_data)
end

Instance Method Details

#measure(state, timings, gauges, captured = :GC) ⇒ Object

Captures in-band GC time and stats.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/trashed/instruments/ruby_gc_profiler.rb', line 15

def measure(state, timings, gauges, captured = :GC)
  timings[:"#{captured}.time"] ||= GC::Profiler.total_time

  if @has_raw_data
    timings[:"#{captured}.count"] ||= GC::Profiler.raw_data.size

    timings[:'GC.interval'] = GC::Profiler.raw_data.map { |data| data[:GC_INVOKE_TIME] }

    GC::Profiler.raw_data.each do |data|
      gauges.concat data.map { |k, v| [ :"GC.Profiler.#{k}", v ] }
    end
  end

  GC::Profiler.clear
end

#start(state, timings, gauges) ⇒ Object

Captures out-of-band GC time and stats.



9
10
11
12
# File 'lib/trashed/instruments/ruby_gc_profiler.rb', line 9

def start(state, timings, gauges)
  GC::Profiler.enable
  measure state, timings, gauges, :OOBGC
end