aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorYehuda Katz <wycats@Yehuda-Katz.local>2009-12-27 14:36:59 -0800
committerYehuda Katz <wycats@Yehuda-Katz.local>2009-12-27 14:36:59 -0800
commit12e43494a748e0144195be12dc19161cc3e4d39f (patch)
treec06f88b7ddf6e41205838cc6f4edd2257a801dcb /activerecord/lib/active_record
parent1c26ba486c23f229a12fea6ccad33e6cb3122b91 (diff)
parent97db79ab3c0af7b6805dcaee99384d96ccb3567d (diff)
downloadrails-12e43494a748e0144195be12dc19161cc3e4d39f.tar.gz
rails-12e43494a748e0144195be12dc19161cc3e4d39f.tar.bz2
rails-12e43494a748e0144195be12dc19161cc3e4d39f.zip
Merge remote branch 'jose/perf'
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/controller_runtime.rb27
-rw-r--r--activerecord/lib/active_record/rails.rb7
2 files changed, 32 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/controller_runtime.rb b/activerecord/lib/active_record/controller_runtime.rb
new file mode 100644
index 0000000000..1281901ae8
--- /dev/null
+++ b/activerecord/lib/active_record/controller_runtime.rb
@@ -0,0 +1,27 @@
+module ActiveRecord
+ module ControllerRuntime
+ extend ActiveSupport::Concern
+
+ attr_internal :db_runtime
+
+ def cleanup_view_runtime
+ if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected?
+ db_rt_before_render = ActiveRecord::Base.connection.reset_runtime
+ runtime = super
+ db_rt_after_render = ActiveRecord::Base.connection.reset_runtime
+ self.db_runtime = db_rt_before_render + db_rt_after_render
+ runtime - db_rt_after_render
+ else
+ super
+ end
+ end
+
+ module ClassMethods
+ def process_log_action(controller)
+ super
+ db_runtime = controller.send :db_runtime
+ logger.info(" ActiveRecord runtime: %.1fms" % db_runtime.to_f) if db_runtime
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/activerecord/lib/active_record/rails.rb b/activerecord/lib/active_record/rails.rb
index ddbc555113..8b22f869bc 100644
--- a/activerecord/lib/active_record/rails.rb
+++ b/activerecord/lib/active_record/rails.rb
@@ -7,6 +7,9 @@ require "action_controller/rails"
module ActiveRecord
class Plugin < Rails::Plugin
plugin_name :active_record
+ include_modules_in "ActiveRecord::Base"
+
+ config.action_controller.include "ActiveRecord::ControllerRuntime"
initializer "active_record.set_configs" do |app|
app.config.active_record.each do |k,v|
@@ -50,8 +53,8 @@ module ActiveRecord
initializer "active_record.notifications" do
require 'active_support/notifications'
- ActiveSupport::Notifications.subscribe("sql") do |name, before, after, result, instrumenter_id, payload|
- ActiveRecord::Base.connection.log_info(payload[:sql], name, after - before)
+ ActiveSupport::Notifications.subscribe("sql") do |name, before, after, instrumenter_id, payload|
+ ActiveRecord::Base.connection.log_info(payload[:sql], payload[:name], (after - before) * 1000)
end
end