groonga-query-log 1.2.8 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/bin/groonga-query-log-analyze +3 -4
  3. data/bin/groonga-query-log-analyze-load +22 -0
  4. data/bin/groonga-query-log-check-command-version-compatibility +2 -2
  5. data/bin/groonga-query-log-check-crash +22 -0
  6. data/bin/groonga-query-log-detect-memory-leak +2 -2
  7. data/bin/groonga-query-log-extract +2 -2
  8. data/bin/groonga-query-log-format-regression-test-logs +2 -2
  9. data/bin/groonga-query-log-replay +3 -5
  10. data/bin/groonga-query-log-run-regression-test +2 -2
  11. data/bin/groonga-query-log-show-running-queries +2 -2
  12. data/bin/groonga-query-log-verify-server +2 -2
  13. data/doc/text/news.md +31 -0
  14. data/groonga-query-log.gemspec +5 -4
  15. data/lib/groonga-query-log.rb +42 -0
  16. data/lib/{groonga/query-log/command-line-utils.rb → groonga-query-log/command-line.rb} +25 -13
  17. data/lib/{groonga/query-log → groonga-query-log}/command-version-compatibility-checker.rb +3 -5
  18. data/lib/groonga-query-log/command/analyze-load.rb +188 -0
  19. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer.rb +60 -44
  20. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer/reporter.rb +15 -20
  21. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer/reporter/console.rb +19 -18
  22. data/lib/groonga-query-log/command/analyzer/reporter/csv.rb +77 -0
  23. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer/reporter/html.rb +32 -16
  24. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer/reporter/json-stream.rb +4 -6
  25. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer/reporter/json.rb +7 -7
  26. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer/sized-grouped-operations.rb +3 -5
  27. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer/sized-statistics.rb +4 -6
  28. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer/streamer.rb +4 -6
  29. data/lib/groonga-query-log/command/check-command-version-compatibility.rb +69 -0
  30. data/lib/groonga-query-log/command/check-crash.rb +169 -0
  31. data/lib/groonga-query-log/command/detect-memory-leak.rb +89 -0
  32. data/lib/groonga-query-log/command/extract.rb +171 -0
  33. data/lib/groonga-query-log/command/format-regression-test-logs.rb +143 -0
  34. data/lib/groonga-query-log/command/replay.rb +117 -0
  35. data/lib/groonga-query-log/command/run-regression-test.rb +432 -0
  36. data/lib/groonga-query-log/command/show-running-queries.rb +78 -0
  37. data/lib/{groonga/query-log/command/replay.rb → groonga-query-log/command/verify-server.rb} +68 -37
  38. data/lib/{groonga/query-log → groonga-query-log}/incompatibility-detector.rb +3 -5
  39. data/lib/{groonga/query-log → groonga-query-log}/memory-leak-detector.rb +3 -7
  40. data/lib/groonga-query-log/parser.rb +173 -0
  41. data/lib/{groonga/query-log → groonga-query-log}/replayer.rb +7 -8
  42. data/lib/{groonga/query-log → groonga-query-log}/response-comparer.rb +3 -5
  43. data/lib/{groonga/query-log → groonga-query-log}/server-verifier.rb +3 -5
  44. data/lib/groonga-query-log/statistic.rb +192 -0
  45. data/lib/{groonga/query-log → groonga-query-log}/version.rb +2 -4
  46. data/lib/groonga/query-log.rb +21 -9
  47. data/lib/groonga/query-log/command/analyzer.rb +18 -0
  48. data/lib/groonga/query-log/command/check-command-version-compatibility.rb +2 -55
  49. data/lib/groonga/query-log/command/detect-memory-leak.rb +3 -78
  50. data/lib/groonga/query-log/command/extract.rb +5 -179
  51. data/lib/groonga/query-log/command/format-regression-test-logs.rb +3 -130
  52. data/lib/groonga/query-log/command/reply.rb +18 -0
  53. data/lib/groonga/query-log/command/run-regression-test.rb +2 -418
  54. data/lib/groonga/query-log/command/show-running-queries.rb +3 -65
  55. data/lib/groonga/query-log/command/verify-server.rb +2 -137
  56. data/test/{test-analyzer.rb → command/test-analyzer.rb} +17 -11
  57. data/test/command/test-extract.rb +9 -18
  58. data/test/command/test-format-regression-test-logs.rb +3 -3
  59. data/test/fixtures/reporter/html.expected +55 -20
  60. data/test/helper.rb +22 -7
  61. data/test/test-incompatibility-detector.rb +3 -3
  62. data/test/test-parser.rb +19 -4
  63. data/test/test-replayer.rb +4 -4
  64. data/test/test-response-comparer.rb +2 -2
  65. metadata +86 -97
  66. data/lib/groonga/query-log/analyzer/statistic.rb +0 -194
  67. data/lib/groonga/query-log/parser.rb +0 -125
  68. data/test/fixtures/run-regression-test/db.new/db +0 -0
  69. data/test/fixtures/run-regression-test/db.new/db.0000000 +0 -0
  70. data/test/fixtures/run-regression-test/db.new/db.0000100 +0 -0
  71. data/test/fixtures/run-regression-test/db.new/db.0000101 +0 -0
  72. data/test/fixtures/run-regression-test/db.new/db.0000102 +0 -0
  73. data/test/fixtures/run-regression-test/db.new/db.0000103 +0 -0
  74. data/test/fixtures/run-regression-test/db.new/db.0000103.c +0 -0
  75. data/test/fixtures/run-regression-test/db.new/db.001 +0 -0
  76. data/test/fixtures/run-regression-test/db.new/db.conf +0 -0
  77. data/test/fixtures/run-regression-test/db.new/groonga.log +0 -165
  78. data/test/fixtures/run-regression-test/db.old/db +0 -0
  79. data/test/fixtures/run-regression-test/db.old/db.0000000 +0 -0
  80. data/test/fixtures/run-regression-test/db.old/db.0000100 +0 -0
  81. data/test/fixtures/run-regression-test/db.old/db.0000101 +0 -0
  82. data/test/fixtures/run-regression-test/db.old/db.0000102 +0 -0
  83. data/test/fixtures/run-regression-test/db.old/db.0000103 +0 -0
  84. data/test/fixtures/run-regression-test/db.old/db.0000103.c +0 -0
  85. data/test/fixtures/run-regression-test/db.old/db.001 +0 -0
  86. data/test/fixtures/run-regression-test/db.old/db.conf +0 -0
  87. data/test/fixtures/run-regression-test/db.old/groonga.log +0 -79
  88. data/test/fixtures/run-regression-test/results/query.log +0 -0
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -14,67 +14,5 @@
14
14
  # License along with this library; if not, write to the Free Software
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
- require "optparse"
18
- require "time"
19
-
20
- require "groonga/query-log/version"
21
- require "groonga/query-log/parser"
22
-
23
- module Groonga
24
- module QueryLog
25
- module Command
26
- class ShowRunningQueries
27
- def initialize
28
- @base_time = nil
29
- end
30
-
31
- def run(command_line)
32
- input_paths = create_parser.parse(command_line)
33
- each_parsing_statistic(input_paths) do |statistic|
34
- timestamp = statistic.start_time.strftime("%Y-%m-%d %H:%M:%S.%6N")
35
- puts("#{timestamp}:#{statistic.raw_command}")
36
- end
37
- true
38
- end
39
-
40
- private
41
- def create_parser
42
- parser = OptionParser.new
43
- parser.version = VERSION
44
- parser.banner += " QUERY_LOG"
45
-
46
- parser.separator("")
47
- parser.separator("Options:")
48
-
49
- parser.on("--base-time=TIME",
50
- "Show running queries at TIME",
51
- "You can use popular time format for TIME such as W3C-DTF",
52
- "(now)") do |base_time|
53
- @base_time = Time.parse(base_time)
54
- end
55
- end
56
-
57
- def each_parsing_statistic(input_paths)
58
- parser = Parser.new
59
- catch do |tag|
60
- input_paths.each do |input_path|
61
- File.open(input_path) do |input|
62
- parser.parse(input) do |statistic|
63
- next if @base_time.nil?
64
- next if statistic.start_time < @base_time
65
- if statistic.start_time == @base_time
66
- yield(statistic)
67
- end
68
- throw(tag)
69
- end
70
- end
71
- end
72
- end
73
- parser.parsing_statistics.each do |statistic|
74
- yield(statistic)
75
- end
76
- end
77
- end
78
- end
79
- end
80
- end
17
+ require "groonga/query-log"
18
+ require "groonga-query-log/command/show-running-queries"
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013-2017 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -14,140 +14,5 @@
14
14
  # License along with this library; if not, write to the Free Software
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
- require "optparse"
18
-
19
17
  require "groonga/query-log"
20
-
21
- module Groonga
22
- module QueryLog
23
- module Command
24
- class VerifyServer
25
- def initialize
26
- @options = ServerVerifier::Options.new
27
- end
28
-
29
- def run(command_line, &callback)
30
- input_paths = create_parser.parse(command_line)
31
- verifier = ServerVerifier.new(@options)
32
- if input_paths.empty?
33
- verifier.verify($stdin, &callback)
34
- else
35
- input_paths.each do |input_path|
36
- File.open(input_path) do |input|
37
- verifier.verify(input, &callback)
38
- end
39
- end
40
- end
41
- true
42
- end
43
-
44
- private
45
- def create_parser
46
- parser = OptionParser.new
47
- parser.version = VERSION
48
- parser.banner += " QUERY_LOG1 QUERY_LOG2 ..."
49
-
50
- parser.separator("")
51
- parser.separator("Options:")
52
-
53
- available_protocols = [:gqtp, :http]
54
- available_protocols_label = "[#{available_protocols.join(', ')}]"
55
-
56
- parser.on("--groonga1-host=HOST",
57
- "Host name or IP address of Groonga server 1",
58
- "[#{@options.groonga1.host}]") do |host|
59
- @options.groonga1.host = host
60
- end
61
-
62
- parser.on("--groonga1-port=PORT", Integer,
63
- "Port number of Groonga server 1",
64
- "[#{@options.groonga1.port}]") do |port|
65
- @options.groonga1.port = port
66
- end
67
-
68
- parser.on("--groonga1-protocol=PROTOCOL", available_protocols,
69
- "Protocol of Groonga server 1",
70
- available_protocols_label) do |protocol|
71
- @options.groonga1.protocol = protocol
72
- end
73
-
74
- parser.on("--groonga2-host=HOST",
75
- "Host name or IP address of Groonga server 2",
76
- "[#{@options.groonga2.host}]") do |host|
77
- @options.groonga2.host = host
78
- end
79
-
80
- parser.on("--groonga2-port=PORT", Integer,
81
- "Port number of Groonga server 2",
82
- "[#{@options.groonga2.port}]") do |port|
83
- @options.groonga2.port = port
84
- end
85
-
86
- parser.on("--groonga2-protocol=PROTOCOL", available_protocols,
87
- "Protocol of Groonga server 2",
88
- available_protocols_label) do |protocol|
89
- @options.groonga2.protocol = protocol
90
- end
91
-
92
- parser.on("--n-clients=N", Integer,
93
- "The max number of concurrency",
94
- "[#{@options.n_clients}]") do |n_clients|
95
- @options.n_clients = n_clients
96
- end
97
-
98
- parser.on("--request-queue-size=SIZE", Integer,
99
- "The size of request queue",
100
- "[auto]") do |size|
101
- @options.request_queue_size = size
102
- end
103
-
104
- parser.on("--disable-cache",
105
- "Add 'cache=no' parameter to request",
106
- "[#{@options.disable_cache?}]") do
107
- @options.disable_cache = true
108
- end
109
-
110
- parser.on("--target-command-name=NAME",
111
- "Add NAME to target command names",
112
- "You can specify this option zero or more times",
113
- "See also --target-command-names") do |name|
114
- @options.target_command_names << name
115
- end
116
-
117
- target_command_names_label = @options.target_command_names.join(", ")
118
- parser.on("--target-command-names=NAME1,NAME2,...", Array,
119
- "Replay only NAME1,NAME2,... commands",
120
- "You can use glob to choose command name",
121
- "[#{target_command_names_label}]") do |names|
122
- @options.target_command_names = names
123
- end
124
-
125
- parser.on("--no-care-order",
126
- "Don't care order of select response records") do
127
- @options.care_order = false
128
- end
129
-
130
- parser.on("--output=PATH",
131
- "Output results to PATH",
132
- "[stdout]") do |path|
133
- @options.output_path = path
134
- end
135
-
136
- parser.on("--[no-]verify-cache",
137
- "Verify cache for each query.",
138
- "[#{@options.verify_cache?}]") do |verify_cache|
139
- @options.verify_cache = verify_cache
140
- end
141
-
142
- parser.separator("Debug options:")
143
- parser.separator("")
144
-
145
- parser.on("--abort-on-exception",
146
- "Abort on exception in threads") do
147
- Thread.abort_on_exception = true
148
- end
149
- end
150
- end
151
- end
152
- end
153
- end
18
+ require "groonga-query-log/command/verify-server"
@@ -1,5 +1,5 @@
1
- # Copyright (C) 2014-2016 Kouhei Sutou <kou@clear-code.com>
2
1
  # Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
2
+ # Copyright (C) 2014-2018 Kouhei Sutou <kou@clear-code.com>
3
3
  #
4
4
  # This library is free software; you can redistribute it and/or
5
5
  # modify it under the terms of the GNU Lesser General Public
@@ -17,17 +17,19 @@
17
17
 
18
18
  require "tempfile"
19
19
  require "pathname"
20
- require "groonga/query-log/analyzer"
20
+ require "groonga-query-log/command/analyzer"
21
+
22
+ class AnalyzerCommandTest < Test::Unit::TestCase
23
+ include Helper::Command
21
24
 
22
- class AnalyzerTest < Test::Unit::TestCase
23
25
  setup
24
26
  def setup_fixtures
25
- @fixtures_path = File.join(File.dirname(__FILE__), "fixtures")
27
+ @fixtures_path = File.join(__dir__, "..", "fixtures")
26
28
  @query_log_path = File.join(@fixtures_path, "query.log")
27
29
  end
28
30
 
29
31
  def setup
30
- @analyzer = Groonga::QueryLog::Analyzer.new
32
+ @analyzer = GroongaQueryLog::Command::Analyzer.new
31
33
  end
32
34
 
33
35
  class TestInputFile < self
@@ -40,9 +42,8 @@ class AnalyzerTest < Test::Unit::TestCase
40
42
  end
41
43
 
42
44
  def test_no_specified
43
- assert_raise(Groonga::QueryLog::Analyzer::NoInputError) do
44
- run_analyzer
45
- end
45
+ assert_equal("Error: Please specify input log files.\n",
46
+ run_analyzer)
46
47
  end
47
48
  end
48
49
 
@@ -101,9 +102,14 @@ class AnalyzerTest < Test::Unit::TestCase
101
102
  private
102
103
  def run_analyzer(*arguments)
103
104
  Tempfile.open("output.actual") do |output|
104
- arguments << "--output" << output.path
105
- @analyzer.run(arguments)
106
- File.read(output.path)
105
+ open_error_output do |error|
106
+ arguments << "--output" << output.path
107
+ if @analyzer.run(arguments)
108
+ File.read(output.path)
109
+ else
110
+ File.read(error.path)
111
+ end
112
+ end
107
113
  end
108
114
  end
109
115
 
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
2
  #
4
3
  # Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
5
- # Copyright (C) 2015 Kouhei Sutou <kou@clear-code.com>
4
+ # Copyright (C) 2015-2018 Kouhei Sutou <kou@clear-code.com>
6
5
  #
7
6
  # This library is free software; you can redistribute it and/or
8
7
  # modify it under the terms of the GNU Lesser General Public
@@ -19,9 +18,11 @@
19
18
 
20
19
  require "stringio"
21
20
  require "groonga/command"
22
- require "groonga/query-log/command/extract"
21
+ require "groonga-query-log/command/extract"
23
22
 
24
23
  class ExtractCommandTest < Test::Unit::TestCase
24
+ include Helper::Command
25
+
25
26
  setup
26
27
  def setup_fixtures
27
28
  @fixtures_path = File.join(File.dirname(__FILE__), "..", "fixtures")
@@ -29,7 +30,7 @@ class ExtractCommandTest < Test::Unit::TestCase
29
30
  end
30
31
 
31
32
  def setup
32
- @extract_command = Groonga::QueryLog::Command::Extract.new
33
+ @extract_command = GroongaQueryLog::Command::Extract.new
33
34
  end
34
35
 
35
36
  class TestInputFile < self
@@ -112,19 +113,6 @@ EOC
112
113
  end
113
114
  end
114
115
 
115
- def open_error_output
116
- Tempfile.open("extract.error") do |error|
117
- error.sync = true
118
- original_stderr = $stderr.dup
119
- $stderr.reopen(error)
120
- begin
121
- yield(error)
122
- ensure
123
- $stderr.reopen(original_stderr)
124
- end
125
- end
126
- end
127
-
128
116
  class TestExtract < self
129
117
  def setup
130
118
  super
@@ -163,8 +151,11 @@ EOL
163
151
 
164
152
  private
165
153
  def extract
154
+ input = Tempfile.new(["groonga-query", ".log"])
155
+ input.puts(@log)
156
+ input.close
166
157
  output = StringIO.new
167
- @extract_command.send(:extract, @log, output)
158
+ @extract_command.send(:extract, [input.path], output)
168
159
  output.string
169
160
  end
170
161
  end
@@ -16,13 +16,13 @@
16
16
  # License along with this library; if not, write to the Free Software
17
17
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 
19
- require "groonga/query-log/command/format-regression-test-logs"
19
+ require "groonga-query-log/command/format-regression-test-logs"
20
20
 
21
21
  class FormatRegressionTestLogsCommandTest < Test::Unit::TestCase
22
- include Path
22
+ include Helper::Path
23
23
 
24
24
  def setup
25
- @command = Groonga::QueryLog::Command::FormatRegressionTestLogs.new
25
+ @command = GroongaQueryLog::Command::FormatRegressionTestLogs.new
26
26
  end
27
27
 
28
28
  def run_command(command_line)
@@ -39,7 +39,8 @@ div.statistics
39
39
 
40
40
  td.elapsed,
41
41
  td.ratio,
42
- td.n
42
+ td.n,
43
+ td.n-records
43
44
  {
44
45
  text-align: right;
45
46
  }
@@ -144,8 +145,19 @@ td.name
144
145
  </div>
145
146
  <div class="statistic-operations">
146
147
  <h3>Operations</h3>
147
- <ol>
148
- </ol>
148
+ <table>
149
+ <thead>
150
+ <tr>
151
+ <th>Nth</th>
152
+ <th>Elapsed(sec)</th>
153
+ <th>Name</th>
154
+ <th>N records</th>
155
+ <th>Context</th>
156
+ </tr>
157
+ </thead>
158
+ <tbody>
159
+ </tbody>
160
+ </table>
149
161
  </div>
150
162
  <div class="statistic-heading">
151
163
  <h3>Command</h3>
@@ -173,23 +185,46 @@ td.name
173
185
  </div>
174
186
  <div class="statistic-operations">
175
187
  <h3>Operations</h3>
176
- <ol>
177
- <li>
178
- <span class="elapsed">0.00084295</span>:
179
- <span class="name">filter</span>:
180
- <span class="context">query: follower:@groonga</span>
181
- </li>
182
- <li>
183
- <span class="elapsed">0.00002795</span>:
184
- <span class="name">select</span>:
185
- <span class="context"></span>
186
- </li>
187
- <li>
188
- <span class="elapsed">0.00019585</span>:
189
- <span class="name">output</span>:
190
- <span class="context">_key,name</span>
191
- </li>
192
- </ol>
188
+ <table>
189
+ <thead>
190
+ <tr>
191
+ <th>Nth</th>
192
+ <th>Elapsed(sec)</th>
193
+ <th>Name</th>
194
+ <th>N records</th>
195
+ <th>Context</th>
196
+ </tr>
197
+ </thead>
198
+ <tbody>
199
+ <tr>
200
+ <td class="n">1</td>
201
+ <td class="elapsed">
202
+ <span class="elapsed">0.00084295</span>
203
+ </td>
204
+ <td class="name">filter</td>
205
+ <td class="n-records">2</td>
206
+ <td class="context">query: follower:@groonga</td>
207
+ </tr>
208
+ <tr>
209
+ <td class="n">2</td>
210
+ <td class="elapsed">
211
+ <span class="elapsed">0.00002795</span>
212
+ </td>
213
+ <td class="name">select</td>
214
+ <td class="n-records">2</td>
215
+ <td class="context"></td>
216
+ </tr>
217
+ <tr>
218
+ <td class="n">3</td>
219
+ <td class="elapsed">
220
+ <span class="elapsed">0.00019585</span>
221
+ </td>
222
+ <td class="name">output</td>
223
+ <td class="n-records">2</td>
224
+ <td class="context">_key,name</td>
225
+ </tr>
226
+ </tbody>
227
+ </table>
193
228
  </div>
194
229
  </div>
195
230
  </body>