Class: GroongaQueryLog::Command::CheckPerformanceRegression::Checker

Inherits:
Object
  • Object
show all
Includes:
Formattable
Defined in:
lib/groonga-query-log/command/check-performance-regression.rb

Instance Method Summary collapse

Constructor Details

#initialize(old_statistics, new_statistics, output, threshold, target_queries) ⇒ Checker

Returns a new instance of Checker.



351
352
353
354
355
356
357
358
359
360
361
# 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

Instance Method Details

#checkObject



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# 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("Query: \#{query_statistic.query}\nMean (old): \#{format_elapsed_time(query_statistic.old_elapsed_time)}\nMean (new): \#{format_elapsed_time(query_statistic.new_elapsed_time)}\nDiff:       \#{format_diff(query_statistic)}\n")

    operation_sets = query_statistic.operation_sets
    operation_sets.each_with_index do |operation_set, nth_operation_set|
      @output.puts("Operation set[\#{nth_operation_set}]:\n")
      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("Operation[\#{index}]: \#{label}\nMean (old): \#{format_elapsed_time(old_elapsed_time)}\nMean (new): \#{format_elapsed_time(new_elapsed_time)}\nDiff:       \#{format_diff(operation_statistic)}\n")
      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("Summary:\nSlow queries:    \#{format_summary(n_slow_queries, n_target_queries)}\nSlow operations: \#{format_summary(n_slow_operations, n_target_operations)}\nCaches (old):    \#{format_summary(n_old_cached_queries, n_all_queries)}\nCaches (new):    \#{format_summary(n_new_cached_queries, n_all_queries)}\n")
  true
end