diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-25 11:11:23 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-25 11:11:23 -0700 |
commit | b7e0408ca922cf51228818edbfdcd5c63e3cb84e (patch) | |
tree | 0313ba10f8f42720b03b51fabc992d84c425d8cb /activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | |
parent | d02f2d2fb213584ce52a231063c948def856f657 (diff) | |
download | rails-b7e0408ca922cf51228818edbfdcd5c63e3cb84e.tar.gz rails-b7e0408ca922cf51228818edbfdcd5c63e3cb84e.tar.bz2 rails-b7e0408ca922cf51228818edbfdcd5c63e3cb84e.zip |
use a hash to collect optional statistics about the instrumentation
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract_adapter.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index c07ba2ac74..4799b693c5 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -36,9 +36,12 @@ module ActiveRecord define_callbacks :checkout, :checkin + @@row_even = true + def initialize(connection, logger = nil) #:nodoc: @active = nil @connection, @logger = connection, logger + @runtime = 0 @query_cache_enabled = false @query_cache = {} end @@ -89,6 +92,11 @@ module ActiveRecord false end + def reset_runtime #:nodoc: + rt, @runtime = @runtime, 0 + rt + end + # QUOTING ================================================== # Override to return the quoted table name. Defaults to column quoting. @@ -191,10 +199,16 @@ module ActiveRecord def log(sql, name) name ||= "SQL" - ActiveSupport::Notifications.instrument("sql.active_record", - :sql => sql, :name => name, :connection_id => object_id) do + instrumenter = ActiveSupport::Notifications.instrumenter + info = {} + + result = instrumenter.instrument("sql.active_record", + {:sql => sql, :name => name, :connection_id => object_id}, info) do yield end + @runtime += info[:elapsed] + + result rescue Exception => e message = "#{e.class.name}: #{e.message}: #{sql}" @logger.debug message if @logger |