aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2011-07-25 11:27:37 +0100
committerRobin Houston <robin@lenny.robin>2011-07-25 21:58:46 +0100
commit8a252f033227b798a1261c73151d9b74b56da3cd (patch)
treef1a1c0a1b7c664be128687d0578fbc5b70891fc8
parent63ac1e4faa8f8a312900cee2b959fa765e718872 (diff)
Add a flag to turn off logging memory usage, as (a) this is a debug setting, and (b) it's not cross-platform anyway (causes issues for people developing on OS X)
-rw-r--r--app/controllers/application_controller.rb17
-rw-r--r--config/general.yml-example6
2 files changed, 17 insertions, 6 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 405327952..fe9ed7ec7 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -46,12 +46,17 @@ class ApplicationController < ActionController::Base
# egrep "CONSUME MEMORY: [0-9]{7} KB" production.log
around_filter :record_memory
def record_memory
- File.read("/proc/#{Process.pid}/status").match(/VmRSS:\s+(\d+)/)
- rss_before_action = $1.to_i
- yield
- File.read("/proc/#{Process.pid}/status").match(/VmRSS:\s+(\d+)/)
- rss_after_action = $1.to_i
- logger.info("PID: #{Process.pid}\tCONSUME MEMORY: #{rss_after_action - rss_before_action} KB\tNow: #{rss_after_action} KB\t#{request.url}")
+ record_memory = MySociety::Config.get('DEBUG_RECORD_MEMORY', false)
+ if record_memory
+ File.read("/proc/#{Process.pid}/status").match(/VmRSS:\s+(\d+)/)
+ rss_before_action = $1.to_i
+ yield
+ File.read("/proc/#{Process.pid}/status").match(/VmRSS:\s+(\d+)/)
+ rss_after_action = $1.to_i
+ logger.info("PID: #{Process.pid}\tCONSUME MEMORY: #{rss_after_action - rss_before_action} KB\tNow: #{rss_after_action} KB\t#{request.url}")
+ else
+ yield
+ end
end
# Set cookie expiry according to "remember me" checkbox, as per "An easier
diff --git a/config/general.yml-example b/config/general.yml-example
index 8a4a0442e..c26a46004 100644
--- a/config/general.yml-example
+++ b/config/general.yml-example
@@ -83,3 +83,9 @@ STAGING_SITE: 1
RECAPTCHA_PUBLIC_KEY: 'x'
RECAPTCHA_PRIVATE_KEY: 'x'
+# For debugging memory problems. If true, the app logs
+# the memory use increase of the Ruby process due to the
+# request (Linux only). Since Ruby never returns memory to the OS, if the
+# existing process previously served a larger request, this won't
+# show any consumption for the later request.
+DEBUG_RECORD_MEMORY: false \ No newline at end of file