Class: GroongaQueryLog::Command::Analyzer::SizedStatistics
- Inherits:
-
Array
- Object
- Array
- GroongaQueryLog::Command::Analyzer::SizedStatistics
- Defined in:
- lib/groonga-query-log/command/analyzer/sized-statistics.rb
Instance Attribute Summary collapse
-
#last_time ⇒ Object
readonly
Returns the value of attribute last_time.
-
#n_responses ⇒ Object
readonly
Returns the value of attribute n_responses.
-
#n_slow_operations ⇒ Object
readonly
Returns the value of attribute n_slow_operations.
-
#n_slow_responses ⇒ Object
readonly
Returns the value of attribute n_slow_responses.
-
#slow_operations ⇒ Object
readonly
Returns the value of attribute slow_operations.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#total_elapsed ⇒ Object
readonly
Returns the value of attribute total_elapsed.
Instance Method Summary collapse
- #<<(statistic) ⇒ Object
- #apply_options(options) ⇒ Object
- #each_slow_operation ⇒ Object
-
#initialize ⇒ SizedStatistics
constructor
A new instance of SizedStatistics.
- #order=(new_order) ⇒ Object
- #period ⇒ Object
- #replace(other) ⇒ Object
- #responses_per_second ⇒ Object
- #slow_response_ratio ⇒ Object
Constructor Details
#initialize ⇒ SizedStatistics
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_time ⇒ Object (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_responses ⇒ Object (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_operations ⇒ Object (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_responses ⇒ Object (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_operations ⇒ Object (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_time ⇒ Object (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_elapsed ⇒ Object (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 () @max_size = [:n_entries] || @max_size self.order = [:order] || @order unless [:report_summary].nil? @collect_slow_statistics = [:report_summary] end @slow_operations.() end |
#each_slow_operation ⇒ Object
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 |
#period ⇒ Object
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_second ⇒ Object
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_ratio ⇒ Object
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 |