aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/log_subscriber.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-07-25 20:46:42 +0200
committerJosé Valim <jose.valim@gmail.com>2010-07-25 20:46:42 +0200
commitff0d842454571d78addd1fe9d4f232b600881b1a (patch)
treea9c07676d888d14ab5f2298dfe676fbb0ab3eb26 /activerecord/lib/active_record/log_subscriber.rb
parent0d0e79398308e6147e59d99a48c7e6d952e5848c (diff)
downloadrails-ff0d842454571d78addd1fe9d4f232b600881b1a.tar.gz
rails-ff0d842454571d78addd1fe9d4f232b600881b1a.tar.bz2
rails-ff0d842454571d78addd1fe9d4f232b600881b1a.zip
Revert the previous three commits.
* AS::Notifications#instrument should not measure anything, it is not its responsibility; * Adding another argument to AS::Notifications#instrument API needs to be properly discussed;
Diffstat (limited to 'activerecord/lib/active_record/log_subscriber.rb')
-rw-r--r--activerecord/lib/active_record/log_subscriber.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb
index 278e192e59..c7ae12977a 100644
--- a/activerecord/lib/active_record/log_subscriber.rb
+++ b/activerecord/lib/active_record/log_subscriber.rb
@@ -1,11 +1,25 @@
module ActiveRecord
class LogSubscriber < ActiveSupport::LogSubscriber
+ def self.runtime=(value)
+ Thread.current["active_record_sql_runtime"] = value
+ end
+
+ def self.runtime
+ Thread.current["active_record_sql_runtime"] ||= 0
+ end
+
+ def self.reset_runtime
+ rt, self.runtime = runtime, 0
+ rt
+ end
+
def initialize
super
@odd_or_even = false
end
def sql(event)
+ self.class.runtime += event.duration
return unless logger.debug?
name = '%s (%.1fms)' % [event.payload[:name], event.duration]
@@ -31,4 +45,4 @@ module ActiveRecord
end
end
-ActiveRecord::LogSubscriber.attach_to :active_record
+ActiveRecord::LogSubscriber.attach_to :active_record \ No newline at end of file