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.



28
29
30
31
32
33
34
35
36
37
38
39
40
# 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

Instance Attribute Details

#end_timeObject (readonly)

Returns the value of attribute end_time.



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

def end_time
  @end_time
end

#n_responsesObject (readonly)

Returns the value of attribute n_responses.



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

def n_responses
  @n_responses
end

#n_slow_operationsObject (readonly)

Returns the value of attribute n_slow_operations.



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

def n_slow_operations
  @n_slow_operations
end

#n_slow_responsesObject (readonly)

Returns the value of attribute n_slow_responses.



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

def n_slow_responses
  @n_slow_responses
end

#slow_operationsObject (readonly)

Returns the value of attribute slow_operations.



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

def slow_operations
  @slow_operations
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



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

def start_time
  @start_time
end

#total_elapsedObject (readonly)

Returns the value of attribute total_elapsed.



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

def total_elapsed
  @total_elapsed
end

Instance Method Details

#<<(statistic) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# 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) ⇒ Object



47
48
49
50
51
52
53
54
# 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_operationObject



104
105
106
107
108
109
110
111
112
113
114
# 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) ⇒ Object



116
117
118
# File 'lib/groonga-query-log/command/analyzer/sized-statistics.rb', line 116

def each_worker(&block)
  @workers.each_value(&block)
end

#order=(new_order) ⇒ Object



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

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

#periodObject



96
97
98
99
100
101
102
# 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) ⇒ Object



70
71
72
73
74
75
76
77
# 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_secondObject



79
80
81
82
83
84
85
86
# 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_ratioObject



88
89
90
91
92
93
94
# 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