Class: Vernier::MemoryLeakDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/vernier/memory_leak_detector.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(idle_time: 0, collect_time:, drain_time: 0, **collector_options) ⇒ MemoryLeakDetector

Returns a new instance of MemoryLeakDetector.



11
12
13
14
15
16
17
# File 'lib/vernier/memory_leak_detector.rb', line 11

def initialize(idle_time: 0, collect_time:, drain_time: 0, **collector_options)
  @idle_time = idle_time
  @collect_time = collect_time
  @drain_time = drain_time
  @collector_options = collector_options
  @thread = nil
end

Class Method Details

.start_threadObject



5
6
7
8
9
# File 'lib/vernier/memory_leak_detector.rb', line 5

def self.start_thread(...)
  detector = new(...)
  detector.start_thread
  detector
end

Instance Method Details

#resultObject



36
37
38
# File 'lib/vernier/memory_leak_detector.rb', line 36

def result
  @thread&.value
end

#start_threadObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vernier/memory_leak_detector.rb', line 19

def start_thread
  @thread = Thread.new do
    sleep @idle_time

    collector = Collector.new(:retained, @collector_options)
    collector.start

    sleep @collect_time

    collector.drain

    sleep @drain_time

    collector.stop
  end
end