Class: GroongaQueryLog::Command::Analyzer

Inherits:
GroongaQueryLog::CommandLine show all
Defined in:
lib/groonga-query-log/command/analyzer.rb,
lib/groonga-query-log/command/analyzer/reporter.rb,
lib/groonga-query-log/command/analyzer/streamer.rb,
lib/groonga-query-log/command/analyzer/reporter/csv.rb,
lib/groonga-query-log/command/analyzer/reporter/html.rb,
lib/groonga-query-log/command/analyzer/reporter/json.rb,
lib/groonga-query-log/command/analyzer/reporter/console.rb,
lib/groonga-query-log/command/analyzer/sized-statistics.rb,
lib/groonga-query-log/command/analyzer/reporter/json-stream.rb,
lib/groonga-query-log/command/analyzer/sized-grouped-operations.rb

Defined Under Namespace

Classes: CSVReporter, ConsoleReporter, HTMLReporter, JSONReporter, JSONStreamReporter, Reporter, SizedGroupedOperations, SizedStatistics, Streamer, UnsupportedReporter

Instance Method Summary collapse

Constructor Details

#initializeAnalyzer

Returns a new instance of Analyzer.



30
31
32
# File 'lib/groonga-query-log/command/analyzer.rb', line 30

def initialize
  setup_options
end

Instance Method Details

#run(arguments) ⇒ Object

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

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

Examples:

analyzer = GroongaQueryLog::Command::Analyzer.new
analyzer.run("--output", "statistics.html",
             "--reporter", "html",
             "query.log")

Parameters:

  • arguments (Array<String>)

    arguments for groonga-query-log-analyze. Please execute “groonga-query-log-analyze –help” or see #setup_options.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/groonga-query-log/command/analyzer.rb', line 49

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

  stream = @options[:stream]
  dynamic_sort = @options[:dynamic_sort]
  statistics = SizedStatistics.new
  statistics.apply_options(@options)
  if stream
    reporter = create_reporter(statistics)
    streamer = Streamer.new(reporter)
    streamer.start
    process_statistic = lambda do |statistic|
      if @options[:stream_all] or statistic.slow?
        streamer << statistic
      end
    end
  elsif dynamic_sort
    process_statistic = lambda do |statistic|
      statistics << statistic
    end
  else
    full_statistics = []
    process_statistic = lambda do |statistic|
      full_statistics << statistic
    end
  end

  begin
    parse(log_paths, &process_statistic)
  rescue Interrupt
    raise unless stream
  rescue Error
    $stderr.puts($!.message)
    return false
  end

  if stream
    streamer.finish
  else
    statistics.replace(full_statistics) unless dynamic_sort

    reporter = create_reporter(statistics)
    reporter.report
  end

  true
end