2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-07 12:02:53 +08:00

Merge pull request #2622 from gschlager/fix_memstats

handle permission denied errors
This commit is contained in:
Sam 2014-08-06 13:58:45 +10:00
commit bc48094d9a

View file

@ -86,12 +86,19 @@ def consume_mapping( map_lines, totals )
return m return m
end 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 abort 'usage: memstats [pid]' unless ARGV.first
pid = ARGV.shift.to_i pid = ARGV.shift.to_i
totals = Hash.new(0) totals = Hash.new(0)
mappings = [] mappings = []
File.open( "/proc/#{pid}/smaps" ) do |smaps| begin
File.open( "/proc/#{pid}/smaps" ) do |smaps|
map_lines = [] map_lines = []
@ -111,6 +118,9 @@ File.open( "/proc/#{pid}/smaps" ) do |smaps|
break break
end end
end end
end
rescue
create_memstats_not_available( totals )
end end
# http://rubyforge.org/snippet/download.php?type=snippet&id=511 # http://rubyforge.org/snippet/download.php?type=snippet&id=511