Class: Wip::ResourceMonitor
- Inherits:
-
Object
- Object
- Wip::ResourceMonitor
- Defined in:
- lib/wip/resource_monitor.rb
Overview
Periodically prints host CPU/memory/process info while a debug step is still running, so a hung or slow step is visible even before it produces output.
Instance Method Summary collapse
-
#initialize(interval: 5, out: $stderr) ⇒ ResourceMonitor
constructor
A new instance of ResourceMonitor.
- #start(label) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(interval: 5, out: $stderr) ⇒ ResourceMonitor
Returns a new instance of ResourceMonitor.
7 8 9 10 |
# File 'lib/wip/resource_monitor.rb', line 7 def initialize(interval: 5, out: $stderr) @interval = interval @out = out end |
Instance Method Details
#start(label) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/wip/resource_monitor.rb', line 12 def start(label) @thread = Thread.new do loop do sleep @interval @out.puts "wip: [debug] still running (#{load_average} | #{memory} | top: #{top_processes}): #{label}" end end end |
#stop ⇒ Object
21 22 23 24 |
# File 'lib/wip/resource_monitor.rb', line 21 def stop @thread&.kill @thread&.join end |