mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +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
|
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
|
||||||
|
Reference in New Issue
Block a user