Class: GroongaQueryLog::Command::Analyzer::SizedGroupedOperations
- Inherits:
-
Array
- Object
- Array
- GroongaQueryLog::Command::Analyzer::SizedGroupedOperations
- Defined in:
- lib/groonga-query-log/command/analyzer/sized-grouped-operations.rb
Instance Method Summary collapse
- #<<(operation) ⇒ Object
- #apply_options(options) ⇒ Object
- #each ⇒ Object
-
#initialize ⇒ SizedGroupedOperations
constructor
A new instance of SizedGroupedOperations.
Constructor Details
#initialize ⇒ SizedGroupedOperations
Returns a new instance of SizedGroupedOperations.
22 23 24 25 |
# File 'lib/groonga-query-log/command/analyzer/sized-grouped-operations.rb', line 22 def initialize @max_size = 10 @sorter = create_sorter end |
Instance Method Details
#<<(operation) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/groonga-query-log/command/analyzer/sized-grouped-operations.rb', line 40 def <<(operation) each do |grouped_operation| if grouped_operation[:name] == operation[:name] and grouped_operation[:context] == operation[:context] elapsed = operation[:relative_elapsed_in_seconds] grouped_operation[:total_elapsed] += elapsed grouped_operation[:n_operations] += 1 replace(sort_by(&@sorter)) return self end end grouped_operation = { :name => operation[:name], :context => operation[:context], :n_operations => 1, :total_elapsed => operation[:relative_elapsed_in_seconds], } buffer_size = @max_size * 100 if size < buffer_size super(grouped_operation) replace(sort_by(&@sorter)) else if @sorter.call(grouped_operation) < @sorter.call(last) super(grouped_operation) sorted_operations = sort_by(&@sorter) sorted_operations.pop replace(sorted_operations) end end self end |
#apply_options(options) ⇒ Object
27 28 29 |
# File 'lib/groonga-query-log/command/analyzer/sized-grouped-operations.rb', line 27 def () @max_size = [:n_entries] end |
#each ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/groonga-query-log/command/analyzer/sized-grouped-operations.rb', line 31 def each i = 0 super do |grouped_operation| break if i >= @max_size i += 1 yield(grouped_operation) end end |