Fixed that benchmarking times for rendering included db runtimes #987 [skaes@web.de]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1070 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 7c8d2f28
...@@ -19,7 +19,11 @@ def render_with_benchmark(template_name = default_template_name, status = "200 O ...@@ -19,7 +19,11 @@ def render_with_benchmark(template_name = default_template_name, status = "200 O
if logger.nil? if logger.nil?
render_without_benchmark(template_name, status) render_without_benchmark(template_name, status)
else else
db_runtime = ActiveRecord::Base.connection.reset_runtime
@rendering_runtime = Benchmark::measure{ render_without_benchmark(template_name, status) }.real @rendering_runtime = Benchmark::measure{ render_without_benchmark(template_name, status) }.real
@db_rt_before_render = db_runtime
@db_rt_after_render = ActiveRecord::Base.connection.reset_runtime
@rendering_runtime -= @db_rt_after_render
end end
end end
...@@ -28,7 +32,7 @@ def perform_action_with_benchmark ...@@ -28,7 +32,7 @@ def perform_action_with_benchmark
perform_action_without_benchmark perform_action_without_benchmark
else else
runtime = [Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001].max runtime = [Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001].max
log_message = "Completed in #{sprintf("%4f", runtime)} (#{(1 / runtime).floor} reqs/sec)" log_message = "Completed in #{sprintf("%.5f", runtime)} (#{(1 / runtime).floor} reqs/sec)"
log_message << rendering_runtime(runtime) if @rendering_runtime log_message << rendering_runtime(runtime) if @rendering_runtime
log_message << active_record_runtime(runtime) if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? log_message << active_record_runtime(runtime) if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected?
logger.info(log_message) logger.info(log_message)
...@@ -37,13 +41,15 @@ def perform_action_with_benchmark ...@@ -37,13 +41,15 @@ def perform_action_with_benchmark
private private
def rendering_runtime(runtime) def rendering_runtime(runtime)
" | Rendering: #{sprintf("%f", @rendering_runtime)} (#{sprintf("%d", (@rendering_runtime / runtime) * 100)}%)" " | Rendering: #{sprintf("%.5f", @rendering_runtime)} (#{sprintf("%d", (@rendering_runtime * 100) / runtime)}%)"
end end
def active_record_runtime(runtime) def active_record_runtime(runtime)
db_runtime = ActiveRecord::Base.connection.reset_runtime db_runtime = ActiveRecord::Base.connection.reset_runtime
db_percentage = (db_runtime / runtime) * 100 db_runtime += @db_rt_before_render if @db_rt_before_render
" | DB: #{sprintf("%f", db_runtime)} (#{sprintf("%d", db_percentage)}%)" db_runtime += @db_rt_after_render if @db_rt_after_render
db_percentage = (db_runtime * 100) / runtime
" | DB: #{sprintf("%.5f", db_runtime)} (#{sprintf("%d", db_percentage)}%)"
end end
end end
end end
*SVN* *SVN*
* Fixed that benchmarking times for rendering included db runtimes #987 [skaes@web.de]
* Fixed boolean queries for t/f fields in PostgreSQL #995 [dave@cherryville.org] * Fixed boolean queries for t/f fields in PostgreSQL #995 [dave@cherryville.org]
* Added that model.items.delete(child) will delete the child, not just set the foreign key to nil, if the child is dependent on the model #978 [bitsweat] * Added that model.items.delete(child) will delete the child, not just set the foreign key to nil, if the child is dependent on the model #978 [bitsweat]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册