From 043ea9a36654bba3d6a8cf8730ddf395d474568f Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Sun, 11 May 2014 21:15:33 +0200 Subject: [PATCH] Fall back to ps in the profiler. If the /proc filesystem doesn't exist we'll fall back to using the `ps` shell command. --- profile/profile_helper.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/profile/profile_helper.rb b/profile/profile_helper.rb index fb39479..a206683 100644 --- a/profile/profile_helper.rb +++ b/profile/profile_helper.rb @@ -5,13 +5,19 @@ require_relative '../lib/oga' Thread.abort_on_exception = true ## -# Returns memory usage in bytes. This relies on the /proc filesystem, it won't -# work without it. +# Returns memory usage in bytes. If /proc exists it is used, otherwise it falls +# back to `ps`. # # @return [Fixnum] # 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 ##