Class: MemprofilerPprof::BlockFlusher
- Inherits:
-
Object
- Object
- MemprofilerPprof::BlockFlusher
- Defined in:
- lib/ruby_memprofiler_pprof/block_flusher.rb
Instance Attribute Summary collapse
-
#collector ⇒ Object
readonly
Returns the value of attribute collector.
Instance Method Summary collapse
-
#initialize(collector, interval: 30, logger: nil, on_flush: nil, priority: nil, yield_gvl: false, proactively_yield_gvl: false) ⇒ BlockFlusher
constructor
A new instance of BlockFlusher.
- #pause ⇒ Object
- #run ⇒ Object
- #start! ⇒ Object
- #stop! ⇒ Object
- #unpause ⇒ Object
Constructor Details
#initialize(collector, interval: 30, logger: nil, on_flush: nil, priority: nil, yield_gvl: false, proactively_yield_gvl: false) ⇒ BlockFlusher
Returns a new instance of BlockFlusher.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ruby_memprofiler_pprof/block_flusher.rb', line 7 def initialize( collector, interval: 30, logger: nil, on_flush: nil, priority: nil, yield_gvl: false, proactively_yield_gvl: false ) @collector = collector @interval = interval @logger = logger @thread = nil @on_flush = on_flush @status_mutex = Mutex.new @status_cvar = ConditionVariable.new @status = :not_started @priority = priority @yield_gvl = yield_gvl @proactively_yield_gvl = proactively_yield_gvl end |
Instance Attribute Details
#collector ⇒ Object (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
#pause ⇒ Object
55 56 57 58 59 60 |
# File 'lib/ruby_memprofiler_pprof/block_flusher.rb', line 55 def pause @status_mutex.synchronize do @is_paused = true @status_cvar.broadcast end end |
#run ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/ruby_memprofiler_pprof/block_flusher.rb', line 46 def run start! begin yield ensure stop! end end |
#start! ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby_memprofiler_pprof/block_flusher.rb', line 24 def start! stop! @status = :running @is_paused = false @thread = Thread.new { flusher_thread } if !@priority.nil? @thread.priority = @priority end @atfork_handler = MemprofilerPprof::Atfork.at_fork(:child, &method(:at_fork_in_child)) end |
#stop! ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ruby_memprofiler_pprof/block_flusher.rb', line 35 def stop! @status_mutex.synchronize do @status = :stop @status_cvar.broadcast end @thread&.join @thread = nil @atfork_handler&.remove! @atfork_handler = nil end |
#unpause ⇒ Object
62 63 64 65 66 67 |
# File 'lib/ruby_memprofiler_pprof/block_flusher.rb', line 62 def unpause @status_mutex.synchronize do @is_paused = false @status_cvar.broadcast end end |