Class: Groonga::QueryLog::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga/query-log/parser.rb

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



26
27
# File 'lib/groonga/query-log/parser.rb', line 26

def initialize
end

Instance Method Details

#parse(input) {|statistics| ... } ⇒ Object

Parses query-log file as stream to Analyzer::Statistics including some informations for each query.

Parameters:

  • input (IO)

    IO for input query log file.

Yields:

  • (statistics)

    if a block is specified, it is called every time a query is finished parsing.

Yield Parameters:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/groonga/query-log/parser.rb', line 38

def parse(input, &block)
  current_statistics = {}
  input.each_line do |line|
    case line
    when /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)\.(\d+)\|(.+?)\|([>:<])/
      year, month, day, hour, minutes, seconds, micro_seconds =
        $1, $2, $3, $4, $5, $6, $7
      context_id = $8
      type = $9
      rest = $POSTMATCH.strip
      time_stamp = Time.local(year, month, day, hour, minutes, seconds,
                              micro_seconds)
      parse_line(current_statistics,
                 time_stamp, context_id, type, rest, &block)
    end
  end
end