Class: GroongaQueryLog::Command::Analyzer::SizedStatistics

Inherits:
Array
  • Object
show all
Defined in:
lib/groonga-query-log/command/analyzer/sized-statistics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSizedStatistics

Returns a new instance of SizedStatistics.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 27

def initialize
  @max_size = 10
  self.order = "-elapsed"
  @start_time = nil
  @last_time = nil
  @n_responses = 0
  @n_slow_responses = 0
  @n_slow_operations = 0
  @slow_operations = SizedGroupedOperations.new
  @total_elapsed = 0
  @collect_slow_statistics = true
end

Instance Attribute Details

#last_timeObject (readonly)

Returns the value of attribute last_time.



26
27
28
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 26

def last_time
  @last_time
end

#n_responsesObject (readonly)

Returns the value of attribute n_responses.



24
25
26
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 24

def n_responses
  @n_responses
end

#n_slow_operationsObject (readonly)

Returns the value of attribute n_slow_operations.



24
25
26
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 24

def n_slow_operations
  @n_slow_operations
end

#n_slow_responsesObject (readonly)

Returns the value of attribute n_slow_responses.



24
25
26
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 24

def n_slow_responses
  @n_slow_responses
end

#slow_operationsObject (readonly)

Returns the value of attribute slow_operations.



25
26
27
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 25

def slow_operations
  @slow_operations
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



26
27
28
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 26

def start_time
  @start_time
end

#total_elapsedObject (readonly)

Returns the value of attribute total_elapsed.



25
26
27
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 25

def total_elapsed
  @total_elapsed
end

Instance Method Details

#<<(statistic) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 54

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) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 45

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_operationObject



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 102

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

#order=(new_order) ⇒ Object



40
41
42
43
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 40

def order=(new_order)
  @order = new_order
  @sorter = create_sorter
end

#periodObject



94
95
96
97
98
99
100
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 94

def period
  if @start_time and @last_time
    @last_time - @start_time
  else
    0
  end
end

#replace(other) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 68

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_secondObject



77
78
79
80
81
82
83
84
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 77

def responses_per_second
  _period = period
  if _period.zero?
    0
  else
    @n_responses.to_f / _period
  end
end

#slow_response_ratioObject



86
87
88
89
90
91
92
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 86

def slow_response_ratio
  if @n_responses.zero?
    0
  else
    (@n_slow_responses.to_f / @n_responses) * 100
  end
end