groonga-query-log 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/text/news.md +9 -0
- data/lib/groonga/query-log/analyzer.rb +7 -2
- data/lib/groonga/query-log/analyzer/reporter/console.rb +11 -3
- data/lib/groonga/query-log/analyzer/reporter/json-stream.rb +49 -0
- data/lib/groonga/query-log/analyzer/reporter/json.rb +1 -25
- data/lib/groonga/query-log/analyzer/sized-statistics.rb +0 -3
- data/lib/groonga/query-log/analyzer/statistic.rb +29 -0
- data/lib/groonga/query-log/version.rb +1 -1
- data/test/fixtures/reporter/json-stream.expected +2 -0
- data/test/fixtures/reporter/json.expected +2 -2
- data/test/test-analyzer.rb +12 -8
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 445e8c02baa8178322d2b5149f9f57026d483803
|
4
|
+
data.tar.gz: a94bf3aa467173b32823c496217e6aa97ad44a4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45c1b525c23c3efecc23fd3ed0f0ac003009c67d0e98af01799d68d7e984e51debc3fcd8484753f0e35a4853eff69f9470a2c90217ead4c20807544074ef5ce7
|
7
|
+
data.tar.gz: 9f4d57caaa380448aefd533753d9aac19f49f83eb57ce7934ef7343ae1c0450e7b7fcdcbfded01c221fb56d39dcc0869668b5a8afe63eb88e8147ae65b6a15d4
|
data/doc/text/news.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# News
|
2
2
|
|
3
|
+
## 1.0.8: 2014-07-23
|
4
|
+
|
5
|
+
### Improvements
|
6
|
+
|
7
|
+
* groonga-query-log-analyzer: Added "slow" information to query and
|
8
|
+
operations.
|
9
|
+
* groonga-query-log-analyzer: Added "json-stream" reporter. It outputs
|
10
|
+
a statistic as a JSON in one line.
|
11
|
+
|
3
12
|
## 1.0.7: 2014-06-23
|
4
13
|
|
5
14
|
### Improvements
|
@@ -23,6 +23,10 @@ require "groonga/query-log/command-line-utils"
|
|
23
23
|
require "groonga/query-log/parser"
|
24
24
|
require "groonga/query-log/analyzer/streamer"
|
25
25
|
require "groonga/query-log/analyzer/sized-statistics"
|
26
|
+
require "groonga/query-log/analyzer/reporter/console"
|
27
|
+
require "groonga/query-log/analyzer/reporter/html"
|
28
|
+
require "groonga/query-log/analyzer/reporter/json"
|
29
|
+
require "groonga/query-log/analyzer/reporter/json-stream"
|
26
30
|
|
27
31
|
module Groonga
|
28
32
|
module QueryLog
|
@@ -175,7 +179,7 @@ module Groonga
|
|
175
179
|
@options[:slow_response_threshold] = threshold
|
176
180
|
end
|
177
181
|
|
178
|
-
available_reporters = ["console", "json", "html"]
|
182
|
+
available_reporters = ["console", "json", "json-stream", "html"]
|
179
183
|
parser.on("--reporter=REPORTER",
|
180
184
|
available_reporters,
|
181
185
|
"Reports statistics by REPORTER.",
|
@@ -210,6 +214,8 @@ module Groonga
|
|
210
214
|
case @options[:reporter]
|
211
215
|
when "json"
|
212
216
|
JSONReporter.new(statistics)
|
217
|
+
when "json-stream"
|
218
|
+
JSONStreamReporter.new(statistics)
|
213
219
|
when "html"
|
214
220
|
HTMLReporter.new(statistics)
|
215
221
|
else
|
@@ -220,7 +226,6 @@ module Groonga
|
|
220
226
|
def create_stream_reporter
|
221
227
|
case @options[:reporter]
|
222
228
|
when "json"
|
223
|
-
require 'json'
|
224
229
|
Groonga::QueryLog::StreamJSONQueryLogReporter.new
|
225
230
|
when "html"
|
226
231
|
raise UnsupportedReporter, "HTML reporter doesn't support --stream."
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
|
-
# Copyright (C) 2011-
|
3
|
+
# Copyright (C) 2011-2014 Kouhei Sutou <kou@clear-code.com>
|
4
4
|
# Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
|
5
5
|
#
|
6
6
|
# This library is free software; you can redistribute it and/or
|
@@ -24,8 +24,16 @@ module Groonga
|
|
24
24
|
class Analyzer
|
25
25
|
class ConsoleReporter < Reporter
|
26
26
|
class Color
|
27
|
-
NAMES = [
|
28
|
-
|
27
|
+
NAMES = [
|
28
|
+
"black",
|
29
|
+
"red",
|
30
|
+
"green",
|
31
|
+
"yellow",
|
32
|
+
"blue",
|
33
|
+
"magenta",
|
34
|
+
"cyan",
|
35
|
+
"white",
|
36
|
+
]
|
29
37
|
|
30
38
|
attr_reader :name
|
31
39
|
def initialize(name, options={})
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014 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 "groonga/query-log/analyzer/reporter"
|
20
|
+
|
21
|
+
module Groonga
|
22
|
+
module QueryLog
|
23
|
+
class Analyzer
|
24
|
+
class JSONStreamReporter < Reporter
|
25
|
+
def report_statistic(statistic)
|
26
|
+
write(format_statistic(statistic))
|
27
|
+
write("\n")
|
28
|
+
@index += 1
|
29
|
+
end
|
30
|
+
|
31
|
+
def start
|
32
|
+
@index = 0
|
33
|
+
end
|
34
|
+
|
35
|
+
def finish
|
36
|
+
end
|
37
|
+
|
38
|
+
def report_summary
|
39
|
+
# TODO
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def format_statistic(statistic)
|
44
|
+
JSON.generate(statistic.to_hash)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -46,31 +46,7 @@ module Groonga
|
|
46
46
|
|
47
47
|
private
|
48
48
|
def format_statistic(statistic)
|
49
|
-
|
50
|
-
"start_time" => statistic.start_time.to_i,
|
51
|
-
"last_time" => statistic.last_time.to_i,
|
52
|
-
"elapsed" => statistic.elapsed_in_seconds,
|
53
|
-
"return_code" => statistic.return_code,
|
54
|
-
}
|
55
|
-
command = statistic.command
|
56
|
-
arguments = command.arguments.collect do |key, value|
|
57
|
-
{"key" => key, "value" => value}
|
58
|
-
end
|
59
|
-
data["command"] = {
|
60
|
-
"raw" => statistic.raw_command,
|
61
|
-
"name" => command.name,
|
62
|
-
"parameters" => arguments,
|
63
|
-
}
|
64
|
-
operations = []
|
65
|
-
statistic.each_operation do |operation|
|
66
|
-
operation_data = {}
|
67
|
-
operation_data["name"] = operation[:name]
|
68
|
-
operation_data["relative_elapsed"] = operation[:relative_elapsed_in_seconds]
|
69
|
-
operation_data["context"] = operation[:context]
|
70
|
-
operations << operation_data
|
71
|
-
end
|
72
|
-
data["operations"] = operations
|
73
|
-
JSON.generate(data)
|
49
|
+
JSON.generate(statistic.to_hash)
|
74
50
|
end
|
75
51
|
end
|
76
52
|
end
|
@@ -18,9 +18,6 @@
|
|
18
18
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
19
19
|
|
20
20
|
require "groonga/query-log/analyzer/sized-grouped-operations"
|
21
|
-
require "groonga/query-log/analyzer/reporter/console"
|
22
|
-
require "groonga/query-log/analyzer/reporter/html"
|
23
|
-
require "groonga/query-log/analyzer/reporter/json"
|
24
21
|
|
25
22
|
module Groonga
|
26
23
|
module QueryLog
|
@@ -118,6 +118,35 @@ module Groonga
|
|
118
118
|
command.name == "select"
|
119
119
|
end
|
120
120
|
|
121
|
+
def to_hash
|
122
|
+
data = {
|
123
|
+
"start_time" => start_time.to_i,
|
124
|
+
"last_time" => last_time.to_i,
|
125
|
+
"elapsed" => elapsed_in_seconds,
|
126
|
+
"return_code" => return_code,
|
127
|
+
"slow" => slow?,
|
128
|
+
}
|
129
|
+
arguments = command.arguments.collect do |key, value|
|
130
|
+
{"key" => key, "value" => value}
|
131
|
+
end
|
132
|
+
data["command"] = {
|
133
|
+
"raw" => raw_command,
|
134
|
+
"name" => command.name,
|
135
|
+
"parameters" => arguments,
|
136
|
+
}
|
137
|
+
operations = []
|
138
|
+
each_operation do |operation|
|
139
|
+
operation_data = {}
|
140
|
+
operation_data["name"] = operation[:name]
|
141
|
+
operation_data["relative_elapsed"] = operation[:relative_elapsed_in_seconds]
|
142
|
+
operation_data["context"] = operation[:context]
|
143
|
+
operation_data["slow"] = operation[:slow?]
|
144
|
+
operations << operation_data
|
145
|
+
end
|
146
|
+
data["operations"] = operations
|
147
|
+
data
|
148
|
+
end
|
149
|
+
|
121
150
|
private
|
122
151
|
def nano_seconds_to_seconds(nano_seconds)
|
123
152
|
nano_seconds / 1000.0 / 1000.0 / 1000.0
|
@@ -0,0 +1,2 @@
|
|
1
|
+
{"start_time":START_TIME,"last_time":LAST_TIME,"elapsed":0.003128856,"return_code":0,"slow":false,"command":{"raw":"load --table Video","name":"load","parameters":[{"key":"table","value":"Video"}]},"operations":[]}
|
2
|
+
{"start_time":START_TIME,"last_time":LAST_TIME,"elapsed":0.00121714,"return_code":0,"slow":false,"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","slow":false},{"name":"select","relative_elapsed":2.7947e-05,"context":null,"slow":false},{"name":"output","relative_elapsed":0.000195852,"context":"_key,name","slow":false}]}
|
@@ -1,4 +1,4 @@
|
|
1
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"}]}
|
2
|
+
{"start_time":START_TIME,"last_time":LAST_TIME,"elapsed":0.003128856,"return_code":0,"slow":false,"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,"slow":false,"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","slow":false},{"name":"select","relative_elapsed":2.7947e-05,"context":null,"slow":false},{"name":"output","relative_elapsed":0.000195852,"context":"_key,name","slow":false}]}
|
4
4
|
]
|
data/test/test-analyzer.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
|
+
# Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
|
3
4
|
# Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
|
4
5
|
#
|
5
6
|
# This library is free software; you can redistribute it and/or
|
@@ -47,12 +48,16 @@ class AnalyzerTest < Test::Unit::TestCase
|
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
50
|
-
data(
|
51
|
-
|
52
|
-
|
51
|
+
data("console" => "console",
|
52
|
+
"HTML" => "html",
|
53
|
+
"JSON" => "json",
|
54
|
+
"JSON stream" => "json-stream")
|
53
55
|
def test_reporter(reporter)
|
54
56
|
actual_result = run_analyzer("--reporter", reporter, @query_log_path)
|
55
|
-
|
57
|
+
case reporter
|
58
|
+
when "json", "json-stream"
|
59
|
+
actual_result = normalize_json(actual_result)
|
60
|
+
end
|
56
61
|
|
57
62
|
expected_result = expected_analyzed_query("reporter/#{reporter}.expected")
|
58
63
|
assert_equal(expected_result, actual_result)
|
@@ -90,10 +95,9 @@ class AnalyzerTest < Test::Unit::TestCase
|
|
90
95
|
end
|
91
96
|
end
|
92
97
|
|
93
|
-
def normalize_json(
|
94
|
-
|
95
|
-
|
96
|
-
json_string.gsub(/(\"last_time\"):\d+/, "\\1:LAST_TIME")
|
98
|
+
def normalize_json(json)
|
99
|
+
json = json.gsub(/("start_time"):\d+/, "\\1:START_TIME")
|
100
|
+
json.gsub(/("last_time"):\d+/, "\\1:LAST_TIME")
|
97
101
|
end
|
98
102
|
|
99
103
|
def expected_analyzed_query(file_name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groonga-query-log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: groonga-command-parser
|
@@ -186,6 +186,7 @@ files:
|
|
186
186
|
- lib/groonga/query-log/analyzer/reporter.rb
|
187
187
|
- lib/groonga/query-log/analyzer/reporter/console.rb
|
188
188
|
- lib/groonga/query-log/analyzer/reporter/html.rb
|
189
|
+
- lib/groonga/query-log/analyzer/reporter/json-stream.rb
|
189
190
|
- lib/groonga/query-log/analyzer/reporter/json.rb
|
190
191
|
- lib/groonga/query-log/analyzer/sized-grouped-operations.rb
|
191
192
|
- lib/groonga/query-log/analyzer/sized-statistics.rb
|
@@ -217,6 +218,7 @@ files:
|
|
217
218
|
- test/fixtures/query.log
|
218
219
|
- test/fixtures/reporter/console.expected
|
219
220
|
- test/fixtures/reporter/html.expected
|
221
|
+
- test/fixtures/reporter/json-stream.expected
|
220
222
|
- test/fixtures/reporter/json.expected
|
221
223
|
- test/groonga-query-log-test-utils.rb
|
222
224
|
- test/run-test.rb
|
@@ -261,6 +263,7 @@ test_files:
|
|
261
263
|
- test/fixtures/other-query.log
|
262
264
|
- test/fixtures/reporter/console.expected
|
263
265
|
- test/fixtures/reporter/html.expected
|
266
|
+
- test/fixtures/reporter/json-stream.expected
|
264
267
|
- test/fixtures/reporter/json.expected
|
265
268
|
- test/fixtures/query.log
|
266
269
|
- test/fixtures/multi.expected
|