diff options
author | José Valim <jose.valim@gmail.com> | 2009-10-07 11:17:50 -0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-10-15 18:18:44 -0300 |
commit | af0d1fa8920793a95fae456d1f5debdc50287eb3 (patch) | |
tree | dfae586337161abfa8567bf085bdb2e68a070cc2 /activerecord/lib | |
parent | 5d0f8abc003cc6edfdb471ada05754580725b353 (diff) | |
download | rails-af0d1fa8920793a95fae456d1f5debdc50287eb3.tar.gz rails-af0d1fa8920793a95fae456d1f5debdc50287eb3.tar.bz2 rails-af0d1fa8920793a95fae456d1f5debdc50287eb3.zip |
Update Orchestra instrumentations and move part of logging to Orchestra.
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 14 | ||||
-rw-r--r-- | activerecord/lib/active_record/instrument.rb | 5 |
3 files changed, 11 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 283aa7ddfc..eae59dfad7 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1,3 +1,4 @@ +require 'benchmark' require 'yaml' require 'set' require 'active_support/dependencies' @@ -11,6 +12,7 @@ require 'active_support/core_ext/hash/indifferent_access' require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/string/behavior' require 'active_support/core_ext/symbol' +require 'active_support/core_ext/benchmark' require 'active_support/core_ext/object/metaclass' module ActiveRecord #:nodoc: diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 694e1e561c..b411fe7526 100755 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -1,4 +1,3 @@ -require 'benchmark' require 'date' require 'bigdecimal' require 'bigdecimal/util' @@ -12,8 +11,6 @@ require 'active_record/connection_adapters/abstract/connection_pool' require 'active_record/connection_adapters/abstract/connection_specification' require 'active_record/connection_adapters/abstract/query_cache' -require 'active_support/core_ext/benchmark' - module ActiveRecord module ConnectionAdapters # :nodoc: # ActiveRecord supports multiple database systems. AbstractAdapter and @@ -33,6 +30,7 @@ module ActiveRecord include Quoting, DatabaseStatements, SchemaStatements include QueryCache include ActiveSupport::Callbacks + define_callbacks :checkout, :checkin @@row_even = true @@ -193,6 +191,7 @@ module ActiveRecord end def log_info(sql, name, ms) + @runtime += ms if @logger && @logger.debug? name = '%s (%.1fms)' % [name || 'SQL', ms] @logger.debug(format_log_entry(name, sql.squeeze(' '))) @@ -200,13 +199,8 @@ module ActiveRecord end protected - def log(sql, name) - event = ActiveSupport::Orchestra.instrument(:sql, :sql => sql, :name => name) do - yield if block_given? - end - @runtime += event.duration - log_info(sql, name, event.duration) - event.result + def log(sql, name, &block) + ActiveSupport::Orchestra.instrument(:sql, :sql => sql, :name => name, &block) rescue Exception => e # Log message and raise exception. # Set last_verification to 0, so that connection gets verified diff --git a/activerecord/lib/active_record/instrument.rb b/activerecord/lib/active_record/instrument.rb new file mode 100644 index 0000000000..06d3e40080 --- /dev/null +++ b/activerecord/lib/active_record/instrument.rb @@ -0,0 +1,5 @@ +require 'active_support/orchestra' + +ActiveSupport::Orchestra.subscribe("sql") do |event| + ActiveRecord::Base.connection.log_info(event.payload[:sql], event.payload[:name], event.duration) +end |