Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 2140

Show
Ignore:
Timestamp:
09/06/05 16:48:18 (3 years ago)
Author:
david
Message:

Added use_silence parameter to ActiveRecord::Base.benchmark that can be passed false to include all logging statements during the benchmark block. Added ActionController::Base.benchmark and ActionController::Base.silence to allow for easy benchmarking and turning off the log

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r2131 r2140  
    11*SVN* 
     2 
     3* Added ActionController::Base.benchmark and ActionController::Base.silence to allow for easy benchmarking and turning off the log 
    24 
    35* Updated vendor copy of html-scanner to support better xml parsing 
  • trunk/actionpack/lib/action_controller/benchmarking.rb

    r2039 r2140  
    77    def self.append_features(base) 
    88      super 
    9       base.class_eval { 
     9      base.extend(ClassMethods) 
     10      base.class_eval do 
    1011        alias_method :perform_action_without_benchmark, :perform_action 
    1112        alias_method :perform_action, :perform_action_with_benchmark 
     
    1314        alias_method :render_without_benchmark, :render 
    1415        alias_method :render, :render_with_benchmark 
    15       } 
     16      end 
     17    end 
     18 
     19    module ClassMethods 
     20      # Log and benchmark the workings of a single block and silence whatever logging that may have happened inside it  
     21      # (unless <tt>use_silence</tt> is set to false). 
     22      def benchmark(title, use_silence = true) 
     23        if logger 
     24          result = nil 
     25          seconds = Benchmark.realtime { result = use_silence ? silence { yield } : yield } 
     26          logger.info "#{title} (#{sprintf("%f", seconds)})" 
     27          result 
     28        else 
     29          yield 
     30        end 
     31      end 
     32 
     33      # Silences the logger for the duration of the block. 
     34      def silence 
     35        old_logger_level, logger.level = logger.level, Logger::ERROR if logger 
     36        yield 
     37      ensure 
     38        logger.level = old_logger_level if logger 
     39      end 
    1640    end 
    1741 
  • trunk/activerecord/CHANGELOG

    r2105 r2140  
    11*SVN* 
     2 
     3* Added use_silence parameter to ActiveRecord::Base.benchmark that can be passed false to include all logging statements during the benchmark block 
    24 
    35* Make sure the schema_info table is created before querying the current version #1903 
  • trunk/activerecord/lib/active_record/base.rb

    r2096 r2140  
    715715      #     project.milestones << Milestone.find(:all) 
    716716      #   end 
    717       def benchmark(title) 
    718         result = nil 
    719         seconds = Benchmark.realtime { result = silence { yield } } 
    720         logger.info "#{title} (#{sprintf("%f", seconds)})" if logger 
    721         return result 
     717      # 
     718      # The loggings of the multiple statements is turned off unless <tt>use_silence</tt> is set to false. 
     719      def benchmark(title, use_silence = true) 
     720        if logger 
     721          result = nil 
     722          seconds = Benchmark.realtime { result = use_silence ? silence { yield } : yield } 
     723          logger.info "#{title} (#{sprintf("%f", seconds)})" 
     724          result 
     725        else 
     726          yield 
     727        end 
    722728      end 
    723729