diff options
-rw-r--r-- | app/controllers/application_controller.rb | 17 | ||||
-rw-r--r-- | config/general.yml-example | 6 |
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 |