[Groonga-commit] groonga/groonga [master] [query-log][analyzer] add --slow-threshold.

アーカイブの一覧に戻る

null+****@clear***** null+****@clear*****
2011年 6月 1日 (水) 14:51:35 JST


Kouhei Sutou	2011-06-01 05:51:35 +0000 (Wed, 01 Jun 2011)

  New Revision: 524a82862733d17b0259b198223802b8a46474a0

  Log:
    [query-log][analyzer] add --slow-threshold.
    
    It's used as slow operation threshold.

  Modified files:
    tools/groonga-query-log-analyzer.rb

  Modified: tools/groonga-query-log-analyzer.rb (+17 -7)
===================================================================
--- tools/groonga-query-log-analyzer.rb    2011-06-01 05:43:46 +0000 (fd81416)
+++ tools/groonga-query-log-analyzer.rb    2011-06-01 05:51:35 +0000 (3de6980)
@@ -38,6 +38,7 @@ class GroongaQueryLogAnaylzer
     @options[:order] = "-elapsed"
     @options[:color] = :auto
     @options[:output] = "-"
+    @options[:slow_threshold] = 0.05
 
     @option_parser = OptionParser.new do |parser|
       parser.banner += " LOG1 ..."
@@ -84,6 +85,13 @@ class GroongaQueryLogAnaylzer
                 "(#{@options[:output]})") do |output|
         @options[:output] = output
       end
+
+      parser.on("--slow-threshold=THRESHOLD",
+                Float,
+                "Use THRESHOLD to detect slow operations.",
+                "(#{@options[:slow_threshold]})") do |threshold|
+        @options[:slow_threshold] = threshold
+      end
     end
   end
 
@@ -296,17 +304,19 @@ class GroongaQueryLogAnaylzer
   class QueryLogReporter
     include Enumerable
 
-    attr_accessor :n_entries
+    attr_accessor :n_entries, :slow_threshold
     def initialize(statistics)
       @statistics = statistics
       @order = "-elapsed"
       @n_entries = 10
+      @slow_threshold = 0.05
       @sorted_statistics = nil
     end
 
     def apply_options(options)
-      self.order = options[:order]
-      self.n_entries = options[:n_entries]
+      self.order = options[:order] || @order
+      self.n_entries = options[:n_entries] || @n_entries
+      self.slow_threshold = options[:slow_threshold] || @slow_threshold
     end
 
     def order=(order)
@@ -347,6 +357,10 @@ class GroongaQueryLogAnaylzer
         end
       end
     end
+
+    def slow?(elapsed)
+      elapsed >= @slow_threshold
+    end
   end
 
   class ConsoleQueryLogReporter < QueryLogReporter
@@ -554,10 +568,6 @@ class GroongaQueryLogAnaylzer
       end
       "%s%s%s" % [color.escape_sequence, text, @reset_color.escape_sequence]
     end
-
-    def slow?(elapsed)
-      elapsed >= 0.05
-    end
   end
 end
 




Groonga-commit メーリングリストの案内
アーカイブの一覧に戻る