mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 20:01:14 +08:00
guard against permission denied errors
reading from /proc/<pid>/smaps is not available inside of Docker container
This commit is contained in:
@ -86,12 +86,19 @@ 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 = []
|
||||
|
||||
File.open( "/proc/#{pid}/smaps" ) do |smaps|
|
||||
begin
|
||||
File.open( "/proc/#{pid}/smaps" ) do |smaps|
|
||||
|
||||
map_lines = []
|
||||
|
||||
@ -111,6 +118,9 @@ File.open( "/proc/#{pid}/smaps" ) do |smaps|
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue
|
||||
create_memstats_not_available( totals )
|
||||
end
|
||||
|
||||
# http://rubyforge.org/snippet/download.php?type=snippet&id=511
|
||||
|
Reference in New Issue
Block a user