groonga-query-log 1.0.6 → 1.0.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb08906bfcd75b268d3a3bed4ba2768e81ab3c9b
4
- data.tar.gz: cc8b5b02688f467c69a99bf768e0549dec253dae
3
+ metadata.gz: d2eefbe93d2c19b8bbcd1bb9500431012c363f7a
4
+ data.tar.gz: dae8822afd3dc89125f8739f81f375c120416143
5
5
  SHA512:
6
- metadata.gz: d6467ae4182b3d7e4c56a2b3652e241a83e9ffb9f969109941ad730ab11c2e957d97b773e4b1fb02b9dddbfaa6ccbe028f0ffacf321f4be3a19042cc0493a68b
7
- data.tar.gz: 53d25ad095f97d429b32c5269f73c6d686702f5308bfeed50a79ce214acc81313271c7447a316ac8a615c6ae0ce473e0354ecfe4071cb9c90b3b1e82bbe526d1
6
+ metadata.gz: 66d45d79027aaf124b7bf470451c832163685b6debed1f24f8a997876066df2795dbfb9bbdda694874b5436c9855782a05057060e3ebca66e0deb6304cff57fe
7
+ data.tar.gz: acecf0d714ab9f5de1c61feb57f6f1a9795aa68655e2ee3a016eb03052f7ee1b138fc5449747d136c5d365b798fa13e9308ad820d4acb419270071167c3564ac
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+
20
+ require "groonga/query-log/command/show-running-queries"
21
+
22
+ command = Groonga::QueryLog::Command::ShowRunningQueries.new
23
+ exit(command.run(ARGV))
data/doc/text/news.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # News
2
2
 
3
+ ## 1.0.7: 2014-06-23
4
+
5
+ ### Improvements
6
+
7
+ * groonga-query-log-show-running-queries: Added a command that shows
8
+ running queries on the specified base time. It will be useful to
9
+ find a query that causes a problem.
10
+
3
11
  ## 1.0.6: 2014-06-02
4
12
 
5
13
  ### Improvements
@@ -0,0 +1,80 @@
1
+ # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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
@@ -27,6 +27,7 @@ module Groonga
27
27
  @options = options
28
28
  @slow_operation_threshold = options[:slow_operation_threshold]
29
29
  @slow_response_threshold = options[:slow_response_threshold]
30
+ @parsing_statistics = {}
30
31
  end
31
32
 
32
33
  # Parses query-log file as stream to
@@ -39,7 +40,6 @@ module Groonga
39
40
  # @yieldparam [Groonga::QueryLog::Analyzer::Statistic] statistic
40
41
  # statistics of each query in log files.
41
42
  def parse(input, &block)
42
- current_statistics = {}
43
43
  input.each_line do |line|
44
44
  next unless line.valid_encoding?
45
45
  case line
@@ -51,26 +51,28 @@ module Groonga
51
51
  rest = $POSTMATCH.strip
52
52
  time_stamp = Time.local(year, month, day, hour, minutes, seconds,
53
53
  micro_seconds)
54
- parse_line(current_statistics,
55
- time_stamp, context_id, type, rest, &block)
54
+ parse_line(time_stamp, context_id, type, rest, &block)
56
55
  end
57
56
  end
58
57
  end
59
58
 
59
+ def parsing_statistics
60
+ @parsing_statistics.values
61
+ end
62
+
60
63
  private
61
- def parse_line(current_statistics,
62
- time_stamp, context_id, type, rest, &block)
64
+ def parse_line(time_stamp, context_id, type, rest, &block)
63
65
  case type
64
66
  when ">"
65
67
  statistic = create_statistic(context_id)
66
68
  statistic.start(time_stamp, rest)
67
- current_statistics[context_id] = statistic
69
+ @parsing_statistics[context_id] = statistic
68
70
  when ":"
69
71
  return unless /\A(\d+) (.+)\((\d+)\)/ =~ rest
70
72
  elapsed = $1
71
73
  name = $2
72
74
  n_records = $3.to_i
73
- statistic = current_statistics[context_id]
75
+ statistic = @parsing_statistics[context_id]
74
76
  return if statistic.nil?
75
77
  statistic.add_operation(:name => name,
76
78
  :elapsed => elapsed.to_i,
@@ -79,7 +81,7 @@ module Groonga
79
81
  return unless /\A(\d+) rc=(-?\d+)/ =~ rest
80
82
  elapsed = $1
81
83
  return_code = $2
82
- statistic = current_statistics.delete(context_id)
84
+ statistic = @parsing_statistics.delete(context_id)
83
85
  return if statistic.nil?
84
86
  statistic.finish(elapsed.to_i, return_code.to_i)
85
87
  block.call(statistic)
@@ -18,6 +18,6 @@
18
18
 
19
19
  module Groonga
20
20
  module QueryLog
21
- VERSION = "1.0.6"
21
+ VERSION = "1.0.7"
22
22
  end
23
23
  end
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.6
4
+ version: 1.0.7
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-06-02 00:00:00.000000000 Z
11
+ date: 2014-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: groonga-command-parser
@@ -159,6 +159,7 @@ executables:
159
159
  - groonga-query-log-extract
160
160
  - groonga-query-log-run-regression-test
161
161
  - groonga-query-log-replay
162
+ - groonga-query-log-show-running-queries
162
163
  - groonga-query-log-detect-memory-leak
163
164
  - groonga-query-log-analyze
164
165
  extensions: []
@@ -174,6 +175,7 @@ files:
174
175
  - bin/groonga-query-log-format-regression-test-logs
175
176
  - bin/groonga-query-log-replay
176
177
  - bin/groonga-query-log-run-regression-test
178
+ - bin/groonga-query-log-show-running-queries
177
179
  - bin/groonga-query-log-verify-server
178
180
  - doc/text/lgpl-2.1.txt
179
181
  - doc/text/news.md
@@ -194,6 +196,7 @@ files:
194
196
  - lib/groonga/query-log/command/format-regression-test-logs.rb
195
197
  - lib/groonga/query-log/command/replay.rb
196
198
  - lib/groonga/query-log/command/run-regression-test.rb
199
+ - lib/groonga/query-log/command/show-running-queries.rb
197
200
  - lib/groonga/query-log/command/verify-server.rb
198
201
  - lib/groonga/query-log/extractor.rb
199
202
  - lib/groonga/query-log/memory-leak-detector.rb