class GroongaQueryLog::Command::CheckPerformanceRegression::Checker
Public Class Methods
new(old_statistics, new_statistics, output, threshold, target_queries)
click to toggle source
# File lib/groonga-query-log/command/check-performance-regression.rb, line 351 def initialize(old_statistics, new_statistics, output, threshold, target_queries) @old_statistics = old_statistics @new_statistics = new_statistics @output = output @threshold = threshold @target_queries = target_queries end
Public Instance Methods
check()
click to toggle source
# File lib/groonga-query-log/command/check-performance-regression.rb, line 363 def check old_statistics = filter_statistics(@old_statistics) new_statistics = filter_statistics(@new_statistics) old_queries = old_statistics.group_by(&:raw_command) new_queries = new_statistics.group_by(&:raw_command) query_statistics = [] old_queries.each_key do |query| query_statistic = QueryStatistic.new(query, old_queries[query], new_queries[query], @threshold) next unless query_statistic.slow? query_statistics << query_statistic end n_slow_queries = 0 n_target_operations = 0 n_slow_operations = 0 query_statistics.sort_by(&:ratio).each do |query_statistic| n_slow_queries += 1 @output.puts(<<-REPORT) Query: #{query_statistic.query} Mean (old): #{format_elapsed_time(query_statistic.old_elapsed_time)} Mean (new): #{format_elapsed_time(query_statistic.new_elapsed_time)} Diff: #{format_diff(query_statistic)} REPORT operation_sets = query_statistic.operation_sets operation_sets.each_with_index do |operation_set, nth_operation_set| @output.puts(<<-REPORT) Operation set[#{nth_operation_set}]: REPORT operation_set.statistics.each do |operation_statistic| n_target_operations += 1 next unless operation_statistic.slow? n_slow_operations += 1 index = operation_statistic.index name = operation_statistic.name context = operation_statistic.context label = [name, context].compact.join(" ") old_elapsed_time = operation_statistic.old_elapsed_time new_elapsed_time = operation_statistic.new_elapsed_time @output.puts(<<-REPORT) Operation[#{index}]: #{label} Mean (old): #{format_elapsed_time(old_elapsed_time)} Mean (new): #{format_elapsed_time(new_elapsed_time)} Diff: #{format_diff(operation_statistic)} REPORT end end end n_all_queries = @old_statistics.size n_target_queries = old_queries.size n_old_cached_queries = count_cached_queries(@old_statistics) n_new_cached_queries = count_cached_queries(@new_statistics) @output.puts(<<-REPORT) Summary: Slow queries: #{format_summary(n_slow_queries, n_target_queries)} Slow operations: #{format_summary(n_slow_operations, n_target_operations)} Caches (old): #{format_summary(n_old_cached_queries, n_all_queries)} Caches (new): #{format_summary(n_new_cached_queries, n_all_queries)} REPORT true end
Private Instance Methods
count_cached_queries(statistics)
click to toggle source
# File lib/groonga-query-log/command/check-performance-regression.rb, line 432 def count_cached_queries(statistics) n_cached_queries = 0 statistics.each do |statistic| n_cached_queries += 1 if statistic.cache_used? end n_cached_queries end
filter_statistics(statistics)
click to toggle source
# File lib/groonga-query-log/command/check-performance-regression.rb, line 440 def filter_statistics(statistics) statistics.find_all do |statistic| target_statistic?(statistic) end end
format_diff(statistic)
click to toggle source
# File lib/groonga-query-log/command/check-performance-regression.rb, line 452 def format_diff(statistic) "%s%s/%+.2f" % [ statistic.diff_elapsed_time < 0 ? "-" : "+", format_elapsed_time(statistic.diff_elapsed_time), statistic.ratio, ] end
format_summary(n_slows, total)
click to toggle source
# File lib/groonga-query-log/command/check-performance-regression.rb, line 460 def format_summary(n_slows, total) if total.zero? percentage = 0.0 else percentage = (n_slows / total.to_f) * 100 end "%d/%d(%6.2f%%)" % [n_slows, total, percentage] end
target_statistic?(statistic)
click to toggle source
# File lib/groonga-query-log/command/check-performance-regression.rb, line 446 def target_statistic?(statistic) return false if statistic.cache_used? return true if @target_queries.empty? @target_queries.include?(statistic.raw_command) end