add some memory logging support
[opensuse:software-o-o.git] / app / controllers / application_controller.rb
1 # Filters added to this controller apply to all controllers in the application.
2 # Likewise, all the methods added will be available for all controllers.
3
4 require 'memory_profiler'
5
6 class ApplicationController < ActionController::Base
7
8   @memory = 0
9   before_filter :memory
10   after_filter :logit
11
12   init_gettext('software')
13
14   def initialize
15     MemoryProfiler.start :string_debug => false
16   end
17
18   def rescue_action_in_public(exception)
19     @message = exception.message
20     if request.xhr?
21       render :template => "error", :layout => false, :status => 404
22     else
23       render :template => 'error', :layout => "application", :status => 404
24     end
25   end
26
27   def memory
28     @memory = `ps -o rss= -p #{$$}`.to_i
29   end
30
31   def logit
32     mu = `ps -o rss= -p #{$$}`.to_i
33     logger.debug "Request took #{mu-@memory} - now #{mu}"
34   end
35   
36 end