Class: ActionController::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/browser-prof.rb

Instance Method Summary collapse

Instance Method Details

#process_with_browser_profiling(request, response, method = :perform_action, *arguments) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/browser-prof.rb', line 3

def process_with_browser_profiling(request, response, method = :perform_action, *arguments)
  browser_output  = request.parameters.key?('browser_profile!') ||
                    (request.parameters[:params] && request.parameters[:params].key?('browser_profile!')) ||
                    ENV["BROWSER_PROFILE"]
  file_output     = request.parameters.key?('file_profile!') ||
                    (request.parameters[:params] && request.parameters[:params].key?('file_profile!')) ||
                    ENV["FILE_PROFILE"]

  if (browser_output or file_output)
    # Only require these files in needed
    require 'ruby-prof'
    require 'ruby-prof/graph_html_printer_enhanced'

    #run the process through a profile block
    profile_results = RubyProf.profile {
      response = process_without_browser_profiling(request,response, method, *arguments);
    }

    #Use the enhanced html printer to get better results
    printer = RubyProf::GraphHtmlPrinterEnhanced.new(profile_results)

    #determine output location
    if file_output
      printer.print(File.new("#{RAILS_ROOT}/log/profile_out.html","w"))
    else
      response.body << printer.print("",0)
    end

    #reset the content length so the profiling data is included in the response
    response.send("set_content_length!")

    response
  else
    process_without_browser_profiling(request, response, method, *arguments)
  end
end