Class: Wip::ResourceMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/wip/resource_monitor.rb

Overview

Periodically prints host CPU/memory/disk-IO/process info while a debug step is still running, so a hung or slow step is visible even before it produces output of its own.

Instance Method Summary collapse

Constructor Details

#initialize(interval: 5, out: $stderr) ⇒ ResourceMonitor

Returns a new instance of ResourceMonitor.



8
9
10
11
12
13
# File 'lib/wip/resource_monitor.rb', line 8

def initialize(interval: 5, out: $stderr)
  @interval = interval
  @out = out
  @last_disk = disk_sectors
  @last_sampled_at = monotonic
end

Instance Method Details

#start(label) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/wip/resource_monitor.rb', line 15

def start(label)
  @thread = Thread.new do
    loop do
      sleep @interval
      @out.puts "wip: [debug] still running (#{snapshot}): #{label}"
    end
  end
end

#stopObject



24
25
26
27
# File 'lib/wip/resource_monitor.rb', line 24

def stop
  @thread&.kill
  @thread&.join
end