[Groonga-commit] groonga/groonga-query-log at f0afe1c [master] Support request output

Back to archive index

Kouhei Sutou null+****@clear*****
Fri May 24 18:45:18 JST 2013


Kouhei Sutou	2013-05-24 18:45:18 +0900 (Fri, 24 May 2013)

  New Revision: f0afe1c39a45f04ac7f94141aaa4fd0aba742c70
  https://github.com/groonga/groonga-query-log/commit/f0afe1c39a45f04ac7f94141aaa4fd0aba742c70

  Message:
    Support request output

  Modified files:
    lib/groonga/query-log/replayer.rb

  Modified: lib/groonga/query-log/replayer.rb (+36 -0)
===================================================================
--- lib/groonga/query-log/replayer.rb    2013-05-24 18:40:57 +0900 (63ad1e1)
+++ lib/groonga/query-log/replayer.rb    2013-05-24 18:45:18 +0900 (4b94172)
@@ -47,10 +47,14 @@ module Groonga
         Thread.new do
           parser = Parser.new
           id = 0
+          @options.create_request_output do |output|
           parser.parse(input) do |statistic|
+            # TODO: validate orignal_source is one line
+            output << statistic.command.original_source
             @queue.push([id, statistic])
             id += 1
           end
+          end
           @options.n_clients.times do
             @queue.push(nil)
           end
@@ -75,6 +79,23 @@ module Groonga
         client.execute(command)
       end
 
+      class NullOutput
+        class << self
+          def open
+            output = new
+            if block_given?
+              yield(output)
+            else
+              output
+            end
+          end
+        end
+
+        def <<(string)
+          string.bytesize
+        end
+      end
+
       class Options
         attr_accessor :host
         attr_accessor :port
@@ -85,6 +106,7 @@ module Groonga
           @port = 10041
           @protocol = :gqtp
           @n_clients = 8
+          @requests_path = nil
         end
 
         def parse(arguments)
@@ -98,6 +120,14 @@ module Groonga
                                &block)
         end
 
+        def create_request_output(&block)
+          if @requests_path
+            File.open(@requests_path, "w", &block)
+          else
+            NullOutput.open(&block)
+          end
+        end
+
         private
         def create_parser
           parser = OptionParser.new
@@ -131,6 +161,12 @@ module Groonga
                     "[#{@n_clients}]") do |n_clients|
             @n_cilents = n_clients
           end
+
+          parser.on("--output-requests=PATH",
+                    "Output requests to PATH",
+                    "[not output]") do |path|
+            @requests_path = path
+          end
         end
       end
     end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index