mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-05-01 08:25:18 -04:00
guard against permission denied errors
reading from /proc/<pid>/smaps is not available inside of Docker container
This commit is contained in:
parent
04682335d4
commit
abe657dfce
1 changed files with 25 additions and 15 deletions
|
@ -86,31 +86,41 @@ 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 = []
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
break if smaps.eof?
|
break if smaps.eof?
|
||||||
line = smaps.readline.strip
|
line = smaps.readline.strip
|
||||||
case line
|
case line
|
||||||
when /\w+:\s+/
|
when /\w+:\s+/
|
||||||
map_lines << line
|
map_lines << line
|
||||||
when /[0-9a-f]+:[0-9a-f]+\s+/
|
when /[0-9a-f]+:[0-9a-f]+\s+/
|
||||||
if map_lines.size > 0 then
|
if map_lines.size > 0 then
|
||||||
mappings << consume_mapping( map_lines, totals )
|
mappings << consume_mapping( map_lines, totals )
|
||||||
|
end
|
||||||
|
map_lines.clear
|
||||||
|
map_lines << line
|
||||||
|
else
|
||||||
|
break
|
||||||
end
|
end
|
||||||
map_lines.clear
|
|
||||||
map_lines << line
|
|
||||||
else
|
|
||||||
break
|
|
||||||
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue