Class: Groonga::QueryLog::Analyzer
- Inherits:
-
Object
- Object
- Groonga::QueryLog::Analyzer
- Includes:
- CommandLineUtils
- Defined in:
- lib/groonga/query-log/analyzer.rb,
lib/groonga/query-log/analyzer/reporter.rb,
lib/groonga/query-log/analyzer/streamer.rb,
lib/groonga/query-log/analyzer/statistic.rb,
lib/groonga/query-log/analyzer/reporter/html.rb,
lib/groonga/query-log/analyzer/reporter/json.rb,
lib/groonga/query-log/analyzer/reporter/console.rb,
lib/groonga/query-log/analyzer/sized-statistics.rb,
lib/groonga/query-log/analyzer/sized-grouped-operations.rb
Defined Under Namespace
Classes: ConsoleReporter, Error, HTMLReporter, JSONReporter, NoInputError, Reporter, SizedGroupedOperations, SizedStatistics, Statistic, Streamer, UnsupportedReporter
Instance Method Summary collapse
-
#initialize ⇒ Analyzer
constructor
A new instance of Analyzer.
-
#run(*arguments) ⇒ Object
Executes analyzer for groonga’s query logs.
Methods included from CommandLineUtils
#log_via_stdin?, #stdin_with_pipe?, #stdin_with_redirect?
Constructor Details
#initialize ⇒ Analyzer
Returns a new instance of Analyzer.
41 42 43 |
# File 'lib/groonga/query-log/analyzer.rb', line 41 def initialize 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.
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 101 102 103 104 105 106 |
# File 'lib/groonga/query-log/analyzer.rb', line 60 def run(*arguments) log_paths = @option_parser.parse!(arguments) stream = @options[:stream] dynamic_sort = @options[:dynamic_sort] statistics = SizedStatistics.new statistics.(@options) parser = Groonga::QueryLog::Parser.new if stream streamer = Streamer.new(create_reporter(statistics)) streamer.start process_statistic = lambda do |statistic| streamer << statistic 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 if log_paths.empty? unless log_via_stdin? raise(NoInputError, "Error: Please specify input log files.") end parser.parse(ARGF, &process_statistic) end log_paths.each do |log_path| File.open(log_path) do |log| parser.parse(log, &process_statistic) end end if stream streamer.finish return end statistics.replace(full_statistics) unless dynamic_sort reporter = create_reporter(statistics) reporter.(@options) reporter.report end |