Class: GroongaQueryLog::Command::AnalyzeLoad

Inherits:
GroongaQueryLog::CommandLine show all
Defined in:
lib/groonga-query-log/command/analyze-load.rb

Instance Method Summary collapse

Constructor Details

#initializeAnalyzeLoad

Returns a new instance of AnalyzeLoad.



25
26
27
28
# File 'lib/groonga-query-log/command/analyze-load.rb', line 25

def initialize
  setup_options
  @pending_entry = nil
end

Instance Method Details

#run(arguments) ⇒ Object

Executes load command analyzer for Groonga’s query logs. “groonga-query-log-analyze-load” command run this method.

If only paths of query log files are specified, this method prints a result of them to console.

Examples:

analyze_load = GroongaQueryLog::Command::AnalyzeLoad.new
analyze_load.run("--output", "statistics.csv",
                 "query.log")

Parameters:

  • arguments (Array<String>)

    arguments for groonga-query-log-analyze-load. Please execute ‘groonga-query-log-analyze-load –help` or see #setup_options.



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/analyze-load.rb', line 45

def run(arguments)
  begin
    log_paths = @option_parser.parse!(arguments)
  rescue OptionParser::InvalidOption => error
    $stderr.puts(error)
    return false
  end

  begin
    open_output do |output|
      report_header(output)
      parse(log_paths) do |statistic|
        report_statistic(output, statistic)
      end
      if @pending_entry
        report_entry(output, @pending_entry)
        @pending_entry = nil
      end
    end
  rescue Interrupt
  rescue Error
    $stderr.puts($!.message)
    return false
  end

  true
end