Module: ActionController::Profiling

Defined in:
lib/ruby-prof/rails_plugin/ruby-prof/lib/profiling.rb

Overview

The ruby-prof module times the performance of actions and reports to the logger. If the Active Record package has been included, a separate timing section for database calls will be added as well.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



7
8
9
10
11
# File 'lib/ruby-prof/rails_plugin/ruby-prof/lib/profiling.rb', line 7

def self.included(base)
  base.class_eval do
    alias_method_chain :perform_action, :profiling
  end
end

Instance Method Details

#perform_action_with_profilingObject



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
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ruby-prof/rails_plugin/ruby-prof/lib/profiling.rb', line 13

def perform_action_with_profiling
  if not logger or
     not logger.level == Logger::DEBUG
    perform_action_without_profiling
  else
    result = RubyProf.profile do
      perform_action_without_profiling
    end
    
    output = StringIO.new
    output << " [#{complete_request_uri rescue "unknown"}]"
    output << "\n\n"
    
    # Create a flat printer
    printer = RubyProf::FlatPrinter.new(result)
    
    # Skip anything less than 1% - which is a lot of
    # stuff in Rails. Don't print the source file
    # its too noisy.
    printer.print(output, {:min_percent => 1,
                           :print_file => false})
    logger.info(output.string)
    
    ## Example for Graph html printer
    #printer = RubyProf::GraphHtmlPrinter.new(result)
    #File.open('c:/temp/request.html', 'w') do |file|
      #printer.print(file, {:min_percent => 1,
                           #:print_file => true})
    #end   
    
    ## Used for KCacheGrind visualizations
    #printer = RubyProf::CallTreePrinter.new(result)
    #File.open('c:/temp/callgrind.out', 'w') do |file|
      #printer.print(file, {:min_percent => 1,
                             #:print_file => true})
    #end          
  end
end