guard against permission denied errors

reading from /proc/<pid>/smaps is not available inside of Docker container
This commit is contained in:
Gerhard Schlager 2014-08-03 11:40:31 +02:00
parent 04682335d4
commit abe657dfce

View file

@ -86,11 +86,18 @@ def consume_mapping( map_lines, totals )
return m
end
def create_memstats_not_available( totals )
Mapping::FIELDS.each do |field|
totals[field] += Float::NAN
end
end
abort 'usage: memstats [pid]' unless ARGV.first
pid = ARGV.shift.to_i
totals = Hash.new(0)
mappings = []
begin
File.open( "/proc/#{pid}/smaps" ) do |smaps|
map_lines = []
@ -112,6 +119,9 @@ File.open( "/proc/#{pid}/smaps" ) do |smaps|
end
end
end
rescue
create_memstats_not_available( totals )
end
# http://rubyforge.org/snippet/download.php?type=snippet&id=511
def format_number( n )