[Groonga-commit] groonga/groonga-query-log at ecb3c2e [master] analyzer: add target filter options

Back to archive index

Kouhei Sutou null+****@clear*****
Fri May 13 11:33:49 JST 2016


Kouhei Sutou	2016-05-13 11:33:49 +0900 (Fri, 13 May 2016)

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

  Message:
    analyzer: add target filter options
    
    New options:
    
      * --target-commands
      * --target-tables

  Added files:
    test/fixtures/target-commands.expected
    test/fixtures/target-tables.expected
  Modified files:
    lib/groonga/query-log/analyzer.rb
    lib/groonga/query-log/parser.rb
    test/test-analyzer.rb

  Modified: lib/groonga/query-log/analyzer.rb (+19 -3)
===================================================================
--- lib/groonga/query-log/analyzer.rb    2016-02-16 14:10:34 +0900 (400b661)
+++ lib/groonga/query-log/analyzer.rb    2016-05-13 11:33:49 +0900 (0a8e96e)
@@ -1,6 +1,4 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright (C) 2011-2013  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2011-2016  Kouhei Sutou <kou �� clear-code.com>
 # Copyright (C) 2012  Haruka Yoshihara <yoshihara �� clear-code.com>
 #
 # This library is free software; you can redistribute it and/or
@@ -115,6 +113,8 @@ module Groonga
         @options[:output] = "-"
         @options[:slow_operation_threshold] = 0.1
         @options[:slow_response_threshold] = 0.2
+        @options[:target_commands] = nil
+        @options[:target_tables] = nil
         @options[:reporter] = "console"
         @options[:dynamic_sort] = true
         @options[:stream] = false
@@ -181,6 +181,22 @@ module Groonga
             @options[:slow_response_threshold] = threshold
           end
 
+          parser.on("--target-commands=COMMAND1,COMMAND2,...",
+                    Array,
+                    "Process only COMMANDS.",
+                    "Example: --target-commands=select,logical_select",
+                    "Process all commands by default") do |commands|
+            @options[:target_commands] = commands
+          end
+
+          parser.on("--target-tables=TABLE1,TABLE2,...",
+                    Array,
+                    "Process only TABLES.",
+                    "Example: --target-tables=Items,Users",
+                    "Process all tables by default") do |tables|
+            @options[:target_tables] = tables
+          end
+
           available_reporters = ["console", "json", "json-stream", "html"]
           parser.on("--reporter=REPORTER",
                     available_reporters,

  Modified: lib/groonga/query-log/parser.rb (+23 -3)
===================================================================
--- lib/groonga/query-log/parser.rb    2016-02-16 14:10:34 +0900 (c37cb35)
+++ lib/groonga/query-log/parser.rb    2016-05-13 11:33:49 +0900 (1ccdac9)
@@ -1,6 +1,4 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright (C) 2011-2013  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2011-2016  Kouhei Sutou <kou �� clear-code.com>
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -27,6 +25,8 @@ module Groonga
         @options = options
         @slow_operation_threshold = options[:slow_operation_threshold]
         @slow_response_threshold = options[:slow_response_threshold]
+        @target_commands = options[:target_commands]
+        @target_tables = options[:target_tables]
         @parsing_statistics = {}
       end
 
@@ -84,6 +84,7 @@ module Groonga
           statistic = @parsing_statistics.delete(context_id)
           return if statistic.nil?
           statistic.finish(elapsed.to_i, return_code.to_i)
+          return unless target_statistic?(statistic)
           block.call(statistic)
         end
       end
@@ -98,6 +99,25 @@ module Groonga
         end
         statistic
       end
+
+      def target_statistic?(statistic)
+        if @target_commands
+          unless @target_commands.include?(statistic.command.name)
+            return false
+          end
+        end
+
+        if @target_tables
+          table = statistic.command["table"]
+          return false if table.nil?
+
+          unless @target_tables.include?(table)
+            return false
+          end
+        end
+
+        true
+      end
     end
   end
 end

  Added: test/fixtures/target-commands.expected (+24 -0) 100644
===================================================================
--- /dev/null
+++ test/fixtures/target-commands.expected    2016-05-13 11:33:49 +0900 (ebe782c)
@@ -0,0 +1,24 @@
+Summary:
+  Threshold:
+    slow response     : 0.2
+    slow operation    : 0.1
+  # of responses      : 1
+  # of slow responses : 0
+  responses/sec       : 821.5981727656638
+  start time          : 2012-12-12 17:39:17.3
+  last time           : 2012-12-12 17:39:17.3
+  period(sec)         : 0.00121714
+  slow response ratio : 0.000%
+  total response time : 0.00121714
+  Slow Operations:
+
+Slow Queries:
+1) [2012-12-12 17:39:17.3-2012-12-12 17:39:17.3 (0.00121714)](0): select --table Users --query follower:@groonga --output_columns _key,name  name: <select>
+  parameters:
+    <table>: <Users>
+    <query>: <follower:@groonga>
+    <output_columns>: <_key,name>
+  1) 0.00084295:     filter(     2) query: follower:@groonga
+  2) 0.00002795:     select(     2)
+  3) 0.00019585:     output(     2) _key,name
+

  Added: test/fixtures/target-tables.expected (+19 -0) 100644
===================================================================
--- /dev/null
+++ test/fixtures/target-tables.expected    2016-05-13 11:33:49 +0900 (4917679)
@@ -0,0 +1,19 @@
+Summary:
+  Threshold:
+    slow response     : 0.2
+    slow operation    : 0.1
+  # of responses      : 1
+  # of slow responses : 0
+  responses/sec       : 319.6056322182932
+  start time          : 2012-12-12 17:39:17.3
+  last time           : 2012-12-12 17:39:17.3
+  period(sec)         : 0.003128856
+  slow response ratio : 0.000%
+  total response time : 0.003128856
+  Slow Operations:
+
+Slow Queries:
+1) [2012-12-12 17:39:17.3-2012-12-12 17:39:17.3 (0.00312886)](0): load --table Video  name: <load>
+  parameters:
+    <table>: <Video>
+

  Modified: test/test-analyzer.rb (+15 -3)
===================================================================
--- test/test-analyzer.rb    2016-02-16 14:10:34 +0900 (d1313ff)
+++ test/test-analyzer.rb    2016-05-13 11:33:49 +0900 (efe805f)
@@ -1,6 +1,4 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright (C) 2014  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2014-2016  Kouhei Sutou <kou �� clear-code.com>
 # Copyright (C) 2012  Haruka Yoshihara <yoshihara �� clear-code.com>
 #
 # This library is free software; you can redistribute it and/or
@@ -80,6 +78,20 @@ class AnalyzerTest < Test::Unit::TestCase
     assert_equal(expected_result, actual_result)
   end
 
+  def test_target_commands
+    actual_result = run_analyzer("--target-commands=select",
+                                 @query_log_path)
+    expected_result = expected_analyzed_query("target-commands.expected")
+    assert_equal(expected_result, actual_result)
+  end
+
+  def test_target_tables
+    actual_result = run_analyzer("--target-tables=Video",
+                                 @query_log_path)
+    expected_result = expected_analyzed_query("target-tables.expected")
+    assert_equal(expected_result, actual_result)
+  end
+
   def test_no_report_summary
     actual_result = run_analyzer("--no-report-summary", @query_log_path)
     expected_result = expected_analyzed_query("no-report-summary.expected")
-------------- next part --------------
HTML����������������������������...
Download 



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