Class: Groonga::QueryLog::Analyzer::SizedStatistics

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSizedStatistics

Returns a new instance of SizedStatistics.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/groonga/query-log/analyzer/sized-statistics.rb', line 33

def initialize
  @max_size = 10
  self.order = "-elapsed"
  @slow_operation_threshold = 0.1
  @slow_response_threshold = 0.2
  @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.



31
32
33
# File 'lib/groonga/query-log/analyzer/sized-statistics.rb', line 31

def last_time
  @last_time
end

#n_responsesObject (readonly)

Returns the value of attribute n_responses.



29
30
31
# File 'lib/groonga/query-log/analyzer/sized-statistics.rb', line 29

def n_responses
  @n_responses
end

#n_slow_operationsObject (readonly)

Returns the value of attribute n_slow_operations.



29
30
31
# File 'lib/groonga/query-log/analyzer/sized-statistics.rb', line 29

def n_slow_operations
  @n_slow_operations
end

#n_slow_responsesObject (readonly)

Returns the value of attribute n_slow_responses.



29
30
31
# File 'lib/groonga/query-log/analyzer/sized-statistics.rb', line 29

def n_slow_responses
  @n_slow_responses
end

#slow_operation_thresholdObject

Returns the value of attribute slow_operation_threshold.



32
33
34
# File 'lib/groonga/query-log/analyzer/sized-statistics.rb', line 32

def slow_operation_threshold
  @slow_operation_threshold
end

#slow_operationsObject (readonly)

Returns the value of attribute slow_operations.



30
31
32
# File 'lib/groonga/query-log/analyzer/sized-statistics.rb', line 30

def slow_operations
  @slow_operations
end

#slow_response_thresholdObject

Returns the value of attribute slow_response_threshold.



32
33
34
# File 'lib/groonga/query-log/analyzer/sized-statistics.rb', line 32

def slow_response_threshold
  @slow_response_threshold
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



31
32
33
# File 'lib/groonga/query-log/analyzer/sized-statistics.rb', line 31

def start_time
  @start_time
end

#total_elapsedObject (readonly)

Returns the value of attribute total_elapsed.



30
31
32
# File 'lib/groonga/query-log/analyzer/sized-statistics.rb', line 30

def total_elapsed
  @total_elapsed
end

Instance Method Details

#<<(statistic) ⇒ Object



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

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



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

def apply_options(options)
  @max_size = options[:n_entries] || @max_size
  self.order = options[:order] || @order
  @slow_operation_threshold =
    options[:slow_operation_threshold] || @slow_operation_threshold
  @slow_response_threshold =
    options[:slow_response_threshold] || @slow_response_threshold
  unless options[:report_summary].nil?
    @collect_slow_statistics = options[:report_summary]
  end
  @slow_operations.apply_options(options)
end

#each_slow_operationObject



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/groonga/query-log/analyzer/sized-statistics.rb', line 114

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



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

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

#periodObject



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

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

#replace(other) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/groonga/query-log/analyzer/sized-statistics.rb', line 80

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



89
90
91
92
93
94
95
96
# File 'lib/groonga/query-log/analyzer/sized-statistics.rb', line 89

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

#slow_response_ratioObject



98
99
100
101
102
103
104
# File 'lib/groonga/query-log/analyzer/sized-statistics.rb', line 98

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