Created
February 20, 2013 13:05
-
-
Save scotchi/4995413 to your computer and use it in GitHub Desktop.
Mini-tool to get the amount of memory being used by a process, *not* the amount of memory plus the size of mmaped files. In other words, it's a way of removing the mmaped size of PIDs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
PID = ARGV.shift | |
smaps ="/proc/#{PID}/smaps" | |
if PID.nil? | |
warn 'You must specify a PID' | |
exit 1 | |
end | |
begin | |
kb = 0 | |
from = nil | |
File.open("/proc/#{PID}/smaps").each do |line| | |
if line =~ /^[0-9a-f]+-[0-9a-f]+/i | |
from = line.chomp[73..-1] if line =~ /^[0-9a-f]+-[0-9a-f]+/i | |
end | |
kb += line.split(/\s+/)[1].to_i if line =~ /^Size:/ && (!from || from.include?('[heap]')) | |
end | |
puts "#{kb / 1024} MB" | |
rescue | |
warn "Couldn't open #{smaps}" | |
exit 2 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment