Class: TuneMyGc::Snapshotter

Inherits:
Object
  • Object
show all
Defined in:
lib/tunemygc/snapshotter.rb

Constant Summary collapse

UNITS_OF_WORK =
/PROCESSING_STARTED|PROCESSING_ENDED/
TERMINATED =
/TERMINATED/
MAX_SAMPLES =
(ENV['RUBY_GC_MAX_SAMPLES'] ? Integer(ENV['RUBY_GC_MAX_SAMPLES']) : 2000)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buf = Queue.new) ⇒ Snapshotter

Returns a new instance of Snapshotter.



15
16
17
18
19
# File 'lib/tunemygc/snapshotter.rb', line 15

def initialize(buf = Queue.new)
  @buffer = buf
  @unit_of_work = false
  @stat_keys = GC.stat.keys
end

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



11
12
13
# File 'lib/tunemygc/snapshotter.rb', line 11

def buffer
  @buffer
end

#stat_keysObject (readonly)

Returns the value of attribute stat_keys.



13
14
15
# File 'lib/tunemygc/snapshotter.rb', line 13

def stat_keys
  @stat_keys
end

#unit_of_workObject

Returns the value of attribute unit_of_work.



12
13
14
# File 'lib/tunemygc/snapshotter.rb', line 12

def unit_of_work
  @unit_of_work
end

Instance Method Details

#clearObject



30
31
32
# File 'lib/tunemygc/snapshotter.rb', line 30

def clear
  @buffer.clear
end

#deqObject



38
39
40
# File 'lib/tunemygc/snapshotter.rb', line 38

def deq
  @buffer.deq
end

#empty?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/tunemygc/snapshotter.rb', line 42

def empty?
  @buffer.empty?
end

#sizeObject



34
35
36
# File 'lib/tunemygc/snapshotter.rb', line 34

def size
  @buffer.size
end

#take(stage, meta = nil) ⇒ Object



21
22
23
# File 'lib/tunemygc/snapshotter.rb', line 21

def take(stage, meta = nil)
  _buffer([TuneMyGc.walltime, TuneMyGc.peak_rss, TuneMyGc.current_rss, stage, GC.stat.values_at(*stat_keys), GC.latest_gc_info, meta, thread_id])
end

#take_raw(snapshot) ⇒ Object

low level interface, for tests and GC callback



26
27
28
# File 'lib/tunemygc/snapshotter.rb', line 26

def take_raw(snapshot)
  _buffer(snapshot)
end