class GroongaQueryLog::Command::Analyzer::SizedStatistics

Attributes

end_time[R]
n_responses[R]
n_slow_operations[R]
n_slow_responses[R]
slow_operations[R]
start_time[R]
total_elapsed[R]

Public Class Methods

new() click to toggle source
# File lib/groonga-query-log/command/analyzer/sized-statistics.rb, line 28
def initialize
  @max_size = 10
  self.order = "-elapsed"
  @start_time = nil
  @end_time = nil
  @n_responses = 0
  @n_slow_responses = 0
  @n_slow_operations = 0
  @slow_operations = SizedGroupedOperations.new
  @total_elapsed = 0
  @collect_slow_statistics = true
  @workers = {}
end

Public Instance Methods

<<(statistic) click to toggle source
Calls superclass method
# File lib/groonga-query-log/command/analyzer/sized-statistics.rb, line 56
def <<(statistic)
  update_statistic(statistic)
  if size < @max_size
    super(statistic)
    replace(self)
  else
    if @sorter.call(statistic) < @sorter.call(last)
      super(statistic)
      replace(self)
    end
  end
  self
end
apply_options(options) click to toggle source
# File lib/groonga-query-log/command/analyzer/sized-statistics.rb, line 47
def apply_options(options)
  @max_size = options[:n_entries] || @max_size
  self.order = options[:order] || @order
  unless options[:report_summary].nil?
    @collect_slow_statistics = options[:report_summary]
  end
  @slow_operations.apply_options(options)
end
each_slow_operation() { |merge| ... } click to toggle source
# File lib/groonga-query-log/command/analyzer/sized-statistics.rb, line 104
def each_slow_operation
  @slow_operations.each do |grouped_operation|
    total_elapsed = grouped_operation[:total_elapsed]
    n_operations = grouped_operation[:n_operations]
    ratios = {
      :total_elapsed_ratio => total_elapsed / @total_elapsed * 100,
      :n_operations_ratio => n_operations / @n_slow_operations.to_f * 100,
    }
    yield(grouped_operation.merge(ratios))
  end
end
each_worker(&block) click to toggle source
# File lib/groonga-query-log/command/analyzer/sized-statistics.rb, line 116
def each_worker(&block)
  @workers.each_value(&block)
end
order=(new_order) click to toggle source
# File lib/groonga-query-log/command/analyzer/sized-statistics.rb, line 42
def order=(new_order)
  @order = new_order
  @sorter = create_sorter
end
period() click to toggle source
# File lib/groonga-query-log/command/analyzer/sized-statistics.rb, line 96
def period
  if @start_time and @end_time
    @end_time - @start_time
  else
    0
  end
end
replace(other) click to toggle source
Calls superclass method
# File lib/groonga-query-log/command/analyzer/sized-statistics.rb, line 70
def replace(other)
  sorted_other = other.sort_by(&@sorter)
  if sorted_other.size > @max_size
    super(sorted_other[0, @max_size])
  else
    super(sorted_other)
  end
end
responses_per_second() click to toggle source
# File lib/groonga-query-log/command/analyzer/sized-statistics.rb, line 79
def responses_per_second
  _period = period
  if _period.zero?
    0
  else
    @n_responses.to_f / _period
  end
end
slow_response_ratio() click to toggle source
# File lib/groonga-query-log/command/analyzer/sized-statistics.rb, line 88
def slow_response_ratio
  if @n_responses.zero?
    0
  else
    (@n_slow_responses.to_f / @n_responses) * 100
  end
end

Private Instance Methods

create_sorter() click to toggle source
# File lib/groonga-query-log/command/analyzer/sized-statistics.rb, line 121
def create_sorter
  case @order
  when "-elapsed"
    lambda do |statistic|
      -statistic.elapsed
    end
  when "elapsed"
    lambda do |statistic|
      statistic.elapsed
    end
  when "-start-time"
    lambda do |statistic|
      -statistic.start_time.to_f
    end
  else
    lambda do |statistic|
      statistic.start_time.to_f
    end
  end
end
update_statistic(statistic) click to toggle source
# File lib/groonga-query-log/command/analyzer/sized-statistics.rb, line 142
def update_statistic(statistic)
  update_worker_statistic(statistic)
  @start_time ||= statistic.start_time
  @start_time = [@start_time, statistic.start_time].min
  @end_time ||= statistic.end_time
  @end_time = [@end_time, statistic.end_time].max
  @n_responses += 1
  @total_elapsed += statistic.elapsed_in_seconds
  return unless @collect_slow_statistics
  if statistic.slow?
    @n_slow_responses += 1
    if statistic.select_family_command?
      statistic.each_operation do |operation|
        next unless operation[:slow?]
        @n_slow_operations += 1
        @slow_operations << operation
      end
    end
  end
end
update_worker_statistic(statistic) click to toggle source
# File lib/groonga-query-log/command/analyzer/sized-statistics.rb, line 163
def update_worker_statistic(statistic)
  id = statistic.context_id
  @workers[id] ||= WorkerStatistic.new(id)
  @workers[id] << statistic
end