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)
require 'ruby-prof'
require 'ruby-prof/graph_html_printer_enhanced'
profile_results = RubyProf.profile {
response = process_without_browser_profiling(request,response, method, *arguments);
}
printer = RubyProf::GraphHtmlPrinterEnhanced.new(profile_results)
if file_output
printer.print(File.new("#{RAILS_ROOT}/log/profile_out.html","w"))
else
response.body << printer.print("",0)
end
response.send("set_content_length!")
response
else
process_without_browser_profiling(request, response, method, *arguments)
end
end
|