From e236180618c785ccf210fcf4847242ca814731d3 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Wed, 21 Mar 2018 16:22:56 +0000 Subject: Add query counts by model to profiler output --- lib/gitlab/profiler.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/gitlab/profiler.rb') diff --git a/lib/gitlab/profiler.rb b/lib/gitlab/profiler.rb index 98a168b43bb..18540e64d4c 100644 --- a/lib/gitlab/profiler.rb +++ b/lib/gitlab/profiler.rb @@ -92,8 +92,8 @@ module Gitlab if type && time @load_times_by_model ||= {} - @load_times_by_model[type] ||= 0 - @load_times_by_model[type] += time.to_f + @load_times_by_model[type] ||= [] + @load_times_by_model[type] << time.to_f end super @@ -135,8 +135,12 @@ module Gitlab def self.log_load_times_by_model(logger) return unless logger.respond_to?(:load_times_by_model) - logger.load_times_by_model.to_a.sort_by(&:last).reverse.each do |(model, time)| - logger.info("#{model} total: #{time.round(2)}ms") + summarised_load_times = logger.load_times_by_model.to_a.map do |(model, times)| + [model, times.count, times.sum] + end + + summarised_load_times.sort_by(&:last).reverse.each do |(model, query_count, time)| + logger.info("#{model} total (#{query_count}): #{time.round(2)}ms") end end end -- cgit v1.2.1