Fall back to ps in the profiler.

If the /proc filesystem doesn't exist we'll fall back to using the `ps` shell
command.
This commit is contained in:
Yorick Peterse 2014-05-11 21:15:33 +02:00
parent 1b58723e7d
commit 043ea9a366
1 changed files with 9 additions and 3 deletions

View File

@ -5,13 +5,19 @@ require_relative '../lib/oga'
Thread.abort_on_exception = true Thread.abort_on_exception = true
## ##
# Returns memory usage in bytes. This relies on the /proc filesystem, it won't # Returns memory usage in bytes. If /proc exists it is used, otherwise it falls
# work without it. # back to `ps`.
# #
# @return [Fixnum] # @return [Fixnum]
# #
def memory_usage def memory_usage
return File.read('/proc/self/status').match(/VmRSS:\s+(\d+)/)[1].to_i * 1024 if File.exists?('/proc')
kb = File.read('/proc/self/status').match(/VmRSS:\s+(\d+)/)[1].to_i
else
kb = `ps -o rss= #{Process.pid}`.strip.to_i
end
return kb * 1024
end end
## ##