mirror of
https://github.com/lloeki/meminfo.git
synced 2025-12-06 10:04:40 +01:00
initial commit
This commit is contained in:
commit
9897ae9e22
8 changed files with 120 additions and 0 deletions
23
lib/meminfo.rb
Normal file
23
lib/meminfo.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
require 'objspace'
|
||||
require 'meminfo/ext'
|
||||
|
||||
# MemInfo gives a handful of methods allowing inspection of process memory use.
|
||||
module MemInfo
|
||||
module_function
|
||||
|
||||
class ProcessNotFound < StandardError; end
|
||||
|
||||
def rss(pid = Process.pid)
|
||||
Integer(ps_rss(pid)) * 1024
|
||||
rescue TypeError
|
||||
raise ProcessNotFound, pid
|
||||
end
|
||||
|
||||
def memsize
|
||||
ObjectSpace.each_object.reduce(0) { |a, e| a + ObjectSpace.memsize_of(e) }
|
||||
end
|
||||
|
||||
private def ps_rss(pid)
|
||||
`ps ax -o rss,pid`.each_line.grep(/^\s*(\d+)\s+#{pid}$/) { $1 }.first
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue