class GroongaQueryLog::Command::Analyzer::SizedGroupedOperations
Public Class Methods
new()
click to toggle source
# File lib/groonga-query-log/command/analyzer/sized-grouped-operations.rb, line 22 def initialize @max_size = 10 @sorter = create_sorter end
Public Instance Methods
<<(operation)
click to toggle source
Calls superclass method
# 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)
click to toggle source
# File lib/groonga-query-log/command/analyzer/sized-grouped-operations.rb, line 27 def apply_options(options) @max_size = options[:n_entries] end
each() { |grouped_operation| ... }
click to toggle source
Calls superclass method
# 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
Private Instance Methods
create_sorter()
click to toggle source
# File lib/groonga-query-log/command/analyzer/sized-grouped-operations.rb, line 74 def create_sorter lambda do |grouped_operation| -grouped_operation[:total_elapsed] end end