Class: Minitest::ShellPs

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/hog.rb

Overview

Return the resident set size (RSS) in kB.

This is fairly foolproof, but probably not the most accurate measure possible since shelling out most likely affects memory usage and isn’t terribly efficient.

Other strategies could be implemented in the future, for instance see NewRelic’s samplers: github.com/newrelic/rpm/blob/release/lib/new_relic/agent/samplers/memory_sampler.rb

Instance Method Summary collapse

Constructor Details

#initialize(pid = Process::pid) ⇒ ShellPs

Returns a new instance of ShellPs.



78
79
80
# File 'lib/minitest/hog.rb', line 78

def initialize(pid = Process::pid)
  @pid = pid
end

Instance Method Details

#callObject

Based off of: zogovic.com/post/59091704817/memory-usage-monitor-in-ruby Example ps output: “ RSSn223124n”



84
85
86
# File 'lib/minitest/hog.rb', line 84

def call
  `ps -o rss -p #{@pid}`.split("\n").last.to_i
end