Class: MemprofilerPprof::BlockFlusher

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_memprofiler_pprof/block_flusher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collector, interval: 30, logger: nil, on_flush: nil) ⇒ BlockFlusher

Returns a new instance of BlockFlusher.



7
8
9
10
11
12
13
# File 'lib/ruby_memprofiler_pprof/block_flusher.rb', line 7

def initialize(collector, interval: 30, logger: nil, on_flush: nil)
  @collector = collector
  @interval = interval
  @logger = logger
  @thread = nil
  @on_flush = on_flush
end

Instance Attribute Details

#collectorObject (readonly)

Returns the value of attribute collector.



5
6
7
# File 'lib/ruby_memprofiler_pprof/block_flusher.rb', line 5

def collector
  @collector
end

Instance Method Details

#runObject



29
30
31
32
33
34
35
36
# File 'lib/ruby_memprofiler_pprof/block_flusher.rb', line 29

def run
  start!
  begin
    yield
  ensure
    stop!
  end
end

#start!Object



15
16
17
18
19
# File 'lib/ruby_memprofiler_pprof/block_flusher.rb', line 15

def start!
  stop!
  @thread = Thread.new { flusher_thread }
  @atfork_handler = MemprofilerPprof::Atfork.at_fork(:child, &method(:at_fork_in_child))
end

#stop!Object



21
22
23
24
25
26
27
# File 'lib/ruby_memprofiler_pprof/block_flusher.rb', line 21

def stop!
  @thread&.kill
  @thread&.join
  @thread = nil
  @atfork_handler&.remove!
  @atfork_handler = nil
end