groonga-query-log 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. data/.yardopts +5 -0
  2. data/Gemfile +21 -0
  3. data/README.md +49 -0
  4. data/Rakefile +51 -0
  5. data/bin/groonga-query-log-analyzer +28 -0
  6. data/doc/text/lgpl-2.1.txt +502 -0
  7. data/doc/text/news.md +5 -0
  8. data/groonga-query-log.gemspec +65 -0
  9. data/lib/groonga/query-log.rb +21 -0
  10. data/lib/groonga/query-log/analyzer.rb +212 -0
  11. data/lib/groonga/query-log/analyzer/reporter.rb +101 -0
  12. data/lib/groonga/query-log/analyzer/reporter/console.rb +291 -0
  13. data/lib/groonga/query-log/analyzer/reporter/html.rb +325 -0
  14. data/lib/groonga/query-log/analyzer/reporter/json.rb +78 -0
  15. data/lib/groonga/query-log/analyzer/sized-grouped-operations.rb +84 -0
  16. data/lib/groonga/query-log/analyzer/sized-statistics.rb +172 -0
  17. data/lib/groonga/query-log/analyzer/statistic.rb +160 -0
  18. data/lib/groonga/query-log/analyzer/streamer.rb +42 -0
  19. data/lib/groonga/query-log/parser.rb +77 -0
  20. data/lib/groonga/query-log/version.rb +23 -0
  21. data/test/command/test-select.rb +162 -0
  22. data/test/fixtures/n_entries.expected +19 -0
  23. data/test/fixtures/no-report-summary.expected +15 -0
  24. data/test/fixtures/order/-elapsed.expected +28 -0
  25. data/test/fixtures/order/-start-time.expected +28 -0
  26. data/test/fixtures/order/elapsed.expected +28 -0
  27. data/test/fixtures/order/start-time.expected +28 -0
  28. data/test/fixtures/query.log +7 -0
  29. data/test/fixtures/reporter/console.expected +28 -0
  30. data/test/fixtures/reporter/html.expected +196 -0
  31. data/test/fixtures/reporter/json.expected +4 -0
  32. data/test/groonga-query-log-test-utils.rb +79 -0
  33. data/test/run-test.rb +43 -0
  34. data/test/test-analyzer.rb +82 -0
  35. data/test/test-parser.rb +90 -0
  36. metadata +235 -0
@@ -0,0 +1,4 @@
1
+ [
2
+ {"start_time":START_TIME,"last_time":LAST_TIME,"elapsed":0.003128856,"return_code":0,"command":{"raw":"load --table Video","name":"load","parameters":[{"key":"table","value":"Video"}]},"operations":[]},
3
+ {"start_time":START_TIME,"last_time":LAST_TIME,"elapsed":0.00121714,"return_code":0,"command":{"raw":"select --table Users --query follower:@groonga --output_columns _key,name","name":"select","parameters":[{"key":"table","value":"Users"},{"key":"query","value":"follower:@groonga"},{"key":"output_columns","value":"_key,name"}]},"operations":[{"name":"filter","relative_elapsed":0.0008429529999999999,"context":"query: follower:@groonga"},{"name":"select","relative_elapsed":2.7947e-05,"context":null},{"name":"output","relative_elapsed":0.000195852,"context":"_key,name"}]}
4
+ ]
@@ -0,0 +1,79 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011-2012 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "cgi"
20
+ require "stringio"
21
+
22
+ require "groonga/command"
23
+
24
+ require "groonga/query-log"
25
+
26
+ module GroongaQueryLogTestUtils
27
+ module CommandParser
28
+ private
29
+ def command(name, parameters)
30
+ command_class = Groonga::Command.find(name)
31
+ command = command_class.new(name, parameters)
32
+ command.original_format = :command
33
+ command
34
+ end
35
+
36
+ def parse_http_path(command, parameters)
37
+ path = "/d/#{command}.json"
38
+ unless parameters.empty?
39
+ uri_parameters = parameters.collect do |key, value|
40
+ [CGI.escape(key.to_s), CGI.escape(value.to_s)].join("=")
41
+ end
42
+ path << "?"
43
+ path << uri_parameters.join("&")
44
+ end
45
+ Groonga::Command::Parser.parse(path)
46
+ end
47
+
48
+ def parse_command_line(command, parameters)
49
+ command_line = "#{command} --output_type json"
50
+ parameters.each do |key, value|
51
+ if /"| / =~ value
52
+ escaped_value = '"' + value.gsub(/"/, '\"') + '"'
53
+ else
54
+ escaped_value = value
55
+ end
56
+ command_line << " --#{key} #{escaped_value}"
57
+ end
58
+ Groonga::Command::Parser.parse(command_line)
59
+ end
60
+ end
61
+
62
+ module HTTPCommandParser
63
+ include CommandParser
64
+
65
+ private
66
+ def parse(command, parameters={})
67
+ parse_http_path(command, parameters)
68
+ end
69
+ end
70
+
71
+ module CommandLineCommandParser
72
+ include CommandParser
73
+
74
+ private
75
+ def parse(command, parameters={})
76
+ parse_command_line(command, parameters)
77
+ end
78
+ end
79
+ end
data/test/run-test.rb ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ $VERBOSE = true
20
+
21
+ $KCODE = "u" if RUBY_VERSION < "1.9"
22
+
23
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
24
+ lib_dir = File.join(base_dir, "lib")
25
+ test_dir = File.join(base_dir, "test")
26
+
27
+ require "test-unit"
28
+ require "test/unit/notify"
29
+
30
+ Test::Unit::Priority.enable
31
+
32
+ $LOAD_PATH.unshift(lib_dir)
33
+
34
+ $LOAD_PATH.unshift(test_dir)
35
+ require "groonga-query-log-test-utils"
36
+
37
+ Dir.glob("#{base_dir}/test/**/test{_,-}*.rb") do |file|
38
+ require file.sub(/\.rb\z/, '')
39
+ end
40
+
41
+ ENV["TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"] ||= "5000"
42
+
43
+ exit Test::Unit::AutoRunner.run
@@ -0,0 +1,82 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "tempfile"
20
+ require "pathname"
21
+ require "groonga/query-log/analyzer"
22
+
23
+ class AnalyzerTest < Test::Unit::TestCase
24
+ setup
25
+ def setup_fixtures
26
+ @fixtures_path = File.join(File.dirname(__FILE__), "fixtures")
27
+ @query_log_path = File.join(@fixtures_path, "query.log")
28
+ end
29
+
30
+ def setup
31
+ @analyzer = Groonga::QueryLog::Analyzer.new
32
+ end
33
+
34
+ data(:console => "console", :html => "html", :json => "json")
35
+ def test_reporter(reporter)
36
+ actual_result = run_analyzer("--reporter", reporter, @query_log_path)
37
+ actual_result = normalize_json(actual_result) if reporter == "json"
38
+
39
+ expected_result = expected_analyzed_query("reporter/#{reporter}.expected")
40
+ assert_equal(expected_result, actual_result)
41
+ end
42
+
43
+ def test_n_entries
44
+ actual_result = run_analyzer("--n-entries=1", @query_log_path)
45
+ expected_result = expected_analyzed_query("n_entries.expected")
46
+ assert_equal(expected_result, actual_result)
47
+ end
48
+
49
+ data(:asc_elapsed => "elapsed", :asc_start_time => "start-time",
50
+ :desc_elapsed => "-elapsed", :desc_start_time => "-start-time")
51
+ def test_order(order)
52
+ actual_result = run_analyzer("--order=#{order}", @query_log_path)
53
+
54
+ expected_result = expected_analyzed_query("order/#{order}.expected")
55
+ assert_equal(expected_result, actual_result)
56
+ end
57
+
58
+ def test_no_report_summary
59
+ actual_result = run_analyzer("--no-report-summary", @query_log_path)
60
+ expected_result = expected_analyzed_query("no-report-summary.expected")
61
+ assert_equal(expected_result, actual_result)
62
+ end
63
+
64
+ private
65
+ def run_analyzer(*arguments)
66
+ Tempfile.open("output.actual") do |output|
67
+ arguments << "--output" << output.path
68
+ @analyzer.run(*arguments)
69
+ File.read(output.path)
70
+ end
71
+ end
72
+
73
+ def normalize_json(json_string)
74
+ json_string = json_string.gsub(/(\"start_time\"):\d+/,
75
+ "\\1:START_TIME")
76
+ json_string.gsub(/(\"last_time\"):\d+/, "\\1:LAST_TIME")
77
+ end
78
+
79
+ def expected_analyzed_query(file_name)
80
+ File.read(File.join(@fixtures_path, file_name))
81
+ end
82
+ end
@@ -0,0 +1,90 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011-2012 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ class ParserTest < Test::Unit::TestCase
20
+ def test_load
21
+ @log = <<-EOL
22
+ 2012-12-13 11:15:21.628105|0x7fff148c8a50|>load --table Video
23
+ 2012-12-13 11:15:21.645119|0x7fff148c8a50|<000000017041150 rc=0
24
+ EOL
25
+ parsed_command = statistics.first.command
26
+ assert_instance_of(Groonga::Command::Load, parsed_command)
27
+ end
28
+
29
+ private
30
+ def statistics
31
+ statistics = []
32
+ parser = Groonga::QueryLog::Parser.new
33
+ parser.parse(StringIO.new(log)) do |statistic|
34
+ statistics << statistic
35
+ end
36
+ statistics
37
+ end
38
+
39
+ def log
40
+ @log
41
+ end
42
+
43
+ class StatisticOperationTest < self
44
+ def setup
45
+ @log = <<-EOL
46
+ 2011-06-02 16:27:04.731685|5091e5c0|>/d/select.join?table=Entries&filter=local_name+%40+%22gsub%22+%26%26+description+%40+%22string%22&sortby=_score&output_columns=_key&drilldown=name,class
47
+ 2011-06-02 16:27:04.733539|5091e5c0|:000000001849451 filter(15)
48
+ 2011-06-02 16:27:04.734978|5091e5c0|:000000003293459 filter(13)
49
+ 2011-06-02 16:27:04.735012|5091e5c0|:000000003327415 select(13)
50
+ 2011-06-02 16:27:04.735096|5091e5c0|:000000003411824 sort(10)
51
+ 2011-06-02 16:27:04.735232|5091e5c0|:000000003547265 output(10)
52
+ 2011-06-02 16:27:04.735606|5091e5c0|:000000003921419 drilldown(3)
53
+ 2011-06-02 16:27:04.735762|5091e5c0|:000000004077552 drilldown(2)
54
+ 2011-06-02 16:27:04.735808|5091e5c0|<000000004123726 rc=0
55
+ EOL
56
+ end
57
+
58
+ def test_context
59
+ operations = statistics.first.operations.collect do |operation|
60
+ [operation[:name], operation[:context]]
61
+ end
62
+ expected = [
63
+ ["filter", "local_name @ \"gsub\""],
64
+ ["filter", "description @ \"string\""],
65
+ ["select", nil],
66
+ ["sort", "_score"],
67
+ ["output", "_key"],
68
+ ["drilldown", "name"],
69
+ ["drilldown", "class"],
70
+ ]
71
+ assert_equal(expected, operations)
72
+ end
73
+
74
+ def test_n_records
75
+ operations = statistics.first.operations.collect do |operation|
76
+ [operation[:name], operation[:n_records]]
77
+ end
78
+ expected = [
79
+ ["filter", 15],
80
+ ["filter", 13],
81
+ ["select", 13],
82
+ ["sort", 10],
83
+ ["output", 10],
84
+ ["drilldown", 3],
85
+ ["drilldown", 2],
86
+ ]
87
+ assert_equal(expected, operations)
88
+ end
89
+ end
90
+ end
metadata ADDED
@@ -0,0 +1,235 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: groonga-query-log
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kouhei Sutou
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: groonga-command
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: test-unit
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: test-unit-notify
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: bundler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: packnga
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: yard
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: redcarpet
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description: ''
143
+ email:
144
+ - kou@clear-code.com
145
+ executables:
146
+ - groonga-query-log-analyzer
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - README.md
151
+ - Rakefile
152
+ - Gemfile
153
+ - groonga-query-log.gemspec
154
+ - lib/groonga/query-log.rb
155
+ - lib/groonga/query-log/parser.rb
156
+ - lib/groonga/query-log/analyzer.rb
157
+ - lib/groonga/query-log/analyzer/streamer.rb
158
+ - lib/groonga/query-log/analyzer/statistic.rb
159
+ - lib/groonga/query-log/analyzer/reporter.rb
160
+ - lib/groonga/query-log/analyzer/sized-grouped-operations.rb
161
+ - lib/groonga/query-log/analyzer/sized-statistics.rb
162
+ - lib/groonga/query-log/analyzer/reporter/console.rb
163
+ - lib/groonga/query-log/analyzer/reporter/json.rb
164
+ - lib/groonga/query-log/analyzer/reporter/html.rb
165
+ - lib/groonga/query-log/version.rb
166
+ - doc/text/news.md
167
+ - doc/text/lgpl-2.1.txt
168
+ - .yardopts
169
+ - test/run-test.rb
170
+ - test/command/test-select.rb
171
+ - test/fixtures/no-report-summary.expected
172
+ - test/fixtures/query.log
173
+ - test/fixtures/order/start-time.expected
174
+ - test/fixtures/order/-elapsed.expected
175
+ - test/fixtures/order/-start-time.expected
176
+ - test/fixtures/order/elapsed.expected
177
+ - test/fixtures/n_entries.expected
178
+ - test/fixtures/reporter/html.expected
179
+ - test/fixtures/reporter/json.expected
180
+ - test/fixtures/reporter/console.expected
181
+ - test/groonga-query-log-test-utils.rb
182
+ - test/test-parser.rb
183
+ - test/test-analyzer.rb
184
+ - bin/groonga-query-log-analyzer
185
+ homepage: https://github.com/groonga/groonga-query-log
186
+ licenses:
187
+ - LGPLv2.1+
188
+ post_install_message:
189
+ rdoc_options: []
190
+ require_paths:
191
+ - lib
192
+ required_ruby_version: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ segments:
199
+ - 0
200
+ hash: 332673278574272449
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
+ none: false
203
+ requirements:
204
+ - - ! '>='
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ segments:
208
+ - 0
209
+ hash: 332673278574272449
210
+ requirements: []
211
+ rubyforge_project:
212
+ rubygems_version: 1.8.23
213
+ signing_key:
214
+ specification_version: 3
215
+ summary: Groonga-query-log is a collection of libarary and tools to process [groonga](http://groonga.org/)'s
216
+ query log. You can write a program to process query log by using groonga-query-log
217
+ as a library. You can analyze your groonga's queries and test with your groonga's
218
+ query log by using groonga-query-log as a tool.
219
+ test_files:
220
+ - test/run-test.rb
221
+ - test/command/test-select.rb
222
+ - test/fixtures/no-report-summary.expected
223
+ - test/fixtures/query.log
224
+ - test/fixtures/order/start-time.expected
225
+ - test/fixtures/order/-elapsed.expected
226
+ - test/fixtures/order/-start-time.expected
227
+ - test/fixtures/order/elapsed.expected
228
+ - test/fixtures/n_entries.expected
229
+ - test/fixtures/reporter/html.expected
230
+ - test/fixtures/reporter/json.expected
231
+ - test/fixtures/reporter/console.expected
232
+ - test/groonga-query-log-test-utils.rb
233
+ - test/test-parser.rb
234
+ - test/test-analyzer.rb
235
+ has_rdoc: