Navigation Menu

Skip to content

Commit

Permalink
Export parsing statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 23, 2014
1 parent 1aa2288 commit 4cc57aa
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/groonga/query-log/parser.rb
Expand Up @@ -27,6 +27,7 @@ def initialize(options={})
@options = options
@slow_operation_threshold = options[:slow_operation_threshold]
@slow_response_threshold = options[:slow_response_threshold]
@parsing_statistics = {}
end

# Parses query-log file as stream to
Expand All @@ -39,7 +40,6 @@ def initialize(options={})
# @yieldparam [Groonga::QueryLog::Analyzer::Statistic] statistic
# statistics of each query in log files.
def parse(input, &block)
current_statistics = {}
input.each_line do |line|
next unless line.valid_encoding?
case line
Expand All @@ -51,26 +51,28 @@ def parse(input, &block)
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)
parse_line(time_stamp, context_id, type, rest, &block)
end
end
end

def parsing_statistics
@parsing_statistics.values
end

private
def parse_line(current_statistics,
time_stamp, context_id, type, rest, &block)
def parse_line(time_stamp, context_id, type, rest, &block)
case type
when ">"
statistic = create_statistic(context_id)
statistic.start(time_stamp, rest)
current_statistics[context_id] = statistic
@parsing_statistics[context_id] = statistic
when ":"
return unless /\A(\d+) (.+)\((\d+)\)/ =~ rest
elapsed = $1
name = $2
n_records = $3.to_i
statistic = current_statistics[context_id]
statistic = @parsing_statistics[context_id]
return if statistic.nil?
statistic.add_operation(:name => name,
:elapsed => elapsed.to_i,
Expand All @@ -79,7 +81,7 @@ def parse_line(current_statistics,
return unless /\A(\d+) rc=(-?\d+)/ =~ rest
elapsed = $1
return_code = $2
statistic = current_statistics.delete(context_id)
statistic = @parsing_statistics.delete(context_id)
return if statistic.nil?
statistic.finish(elapsed.to_i, return_code.to_i)
block.call(statistic)
Expand Down

0 comments on commit 4cc57aa

Please sign in to comment.