[Groonga-commit] groonga/groonga [master] [query-log][analyzer] add --n-entries option.

Back to archive index

null+****@clear***** null+****@clear*****
2011年 5月 31日 (火) 11:12:15 JST


Kouhei Sutou	2011-05-31 02:12:15 +0000 (Tue, 31 May 2011)

  New Revision: 002b7213958d4f78b5aac1d68b36410021ccc8fc

  Log:
    [query-log][analyzer] add --n-entries option.

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

  Modified: tools/groonga-analyze-query-log.rb (+11 -2)
===================================================================
--- tools/groonga-analyze-query-log.rb    2011-05-30 01:57:42 +0000 (604d917)
+++ tools/groonga-analyze-query-log.rb    2011-05-31 02:12:15 +0000 (ba8885f)
@@ -5,9 +5,17 @@ require 'ostruct'
 require 'optparse'
 
 options = OpenStruct.new
+options.n_entries = 10
 
 option_parser = OptionParser.new do |parser|
   parser.banner += " LOG1 ..."
+
+  parser.on("-n", "--n-entries=N",
+            Integer,
+            "Show top N entries",
+            "(#{options.n_entries})") do |n|
+    options.n_entries = n
+  end
 end
 
 option_parser.parse!(ARGV)
@@ -99,8 +107,9 @@ elapsed_sorted_statistics = statistics.sort_by do |statistic|
   -statistic.elapsed
 end
 
-elapsed_sorted_statistics[0, 10].each_with_index do |statistic, i|
-  puts "%2d) %s" % [i + 1, statistic.label]
+digit = Math.log10(options.n_entries).truncate + 1
+elapsed_sorted_statistics[0, options.n_entries].each_with_index do |statistic, i|
+  puts "%*d) %s" % [digit, i + 1, statistic.label]
   statistic.each_trace_report do |report|
     puts "   #{report}"
   end




Groonga-commit メーリングリストの案内
Back to archive index