Class: Vernier::Collector::RetainedCollector

Inherits:
Vernier::Collector show all
Defined in:
lib/vernier/collector.rb

Instance Attribute Summary

Attributes inherited from Vernier::Collector

#stack_table

Instance Method Summary collapse

Methods inherited from Vernier::Collector

#add_marker, #current_time, new, #record_interval, #stop

Constructor Details

#initialize(mode, options) ⇒ RetainedCollector

Returns a new instance of RetainedCollector.



48
49
50
51
52
53
54
# File 'lib/vernier/collector.rb', line 48

def initialize(mode, options)
  @stack_table = StackTable.new
  @heap_tracker = HeapTracker.new(@stack_table)

  @started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
  super
end

Instance Method Details

#drainObject



60
61
62
# File 'lib/vernier/collector.rb', line 60

def drain
  @heap_tracker.drain
end

#finishObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/vernier/collector.rb', line 64

def finish
  @heap_tracker.drain

  GC.start

  @stack_table.finalize

  GC.start

  @heap_tracker.lock
  tracker_data = @heap_tracker.data

  samples = tracker_data.fetch(:samples)
  weights = tracker_data.fetch(:weights)

  result = Result.new
  result.instance_variable_set(:@threads, {
    0 => {
      tid: 0,
      name: "retained memory",
      started_at: @started_at,
      samples: samples,
      weights: weights,
      sample_categories: [0] * samples.size,
    }
  })
  result.instance_variable_set(:@meta, {
    started_at: @started_at
  })
  result
end

#startObject



56
57
58
# File 'lib/vernier/collector.rb', line 56

def start
  @heap_tracker.collect
end