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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 936e5bb7d220b45ad689535247237ae74e608af5
4
- data.tar.gz: 3700a2ab52b0b28ae308e3ab8edf2629143cb499
3
+ metadata.gz: 213e0534e4b93c131e48f76cfe2c6f8c7fea4a44
4
+ data.tar.gz: 326a76731faf0f948a8362800748503036dca728
5
5
  SHA512:
6
- metadata.gz: 93f1cfd0210554b770fe7d230994939f7dccbbbc2d5ee5dcedaaf06ad1ada4dee88f96f4269c35d0fb63eafdafd5905e14570b15c2124433f40113dc2b621d32
7
- data.tar.gz: '09d0648d52be723c0acda34cf01ae02b1dcb1105ac02e828a1cbad8a53c178b81238eb1535de5e3816c56824881396994bcdc1619466226f1701a2770af6ad58'
6
+ metadata.gz: 55fd3f7d8ed2fa51f94ed333e8afeaaef19ad5230b2a4ab8c0ce9622cde117891e3c26bda0f78a0560dcb0382a3b09c843c09cc474cb62faf3b3607a59d51b44
7
+ data.tar.gz: eff099b4e055fc9e6e332a4d8bd8ae1987596ddab11fc842e83d965603147b68270395102cc9860cc09fb13e6004ebaf2a2bf8a949552bb9712e16552ff7bc5f
@@ -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) 2014 Kouhei Sutou <kou@clear-code.com>
4
+ # Copyright (C) 2014-2017 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
@@ -18,7 +17,7 @@
18
17
  # License along with this library; if not, write to the Free Software
19
18
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
19
 
21
- require "groonga/query-log"
20
+ require "groonga-query-log/command/analyzer"
22
21
 
23
- analyzer = Groonga::QueryLog::Analyzer.new
22
+ analyzer = GroongaQueryLog::Command::Analyzer.new
24
23
  exit(analyzer.run(ARGV))
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2017-2018 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/command/analyze-load"
20
+
21
+ analyze_load = GroongaQueryLog::Command::AnalyzeLoad.new
22
+ exit(analyze_load.run(ARGV))
@@ -16,7 +16,7 @@
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/check-command-version-compatibility"
19
+ require "groonga-query-log/command/check-command-version-compatibility"
20
20
 
21
- command = Groonga::QueryLog::Command::CheckCommandVersionCompatibility.new
21
+ command = GroongaQueryLog::Command::CheckCommandVersionCompatibility.new
22
22
  exit(command.run(ARGV))
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2018 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/command/check-crash"
20
+
21
+ check_crash = GroongaQueryLog::Command::CheckCrash.new
22
+ exit(check_crash.run(ARGV))
@@ -17,7 +17,7 @@
17
17
  # License along with this library; if not, write to the Free Software
18
18
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
 
20
- require "groonga/query-log/command/detect-memory-leak"
20
+ require "groonga-query-log/command/detect-memory-leak"
21
21
 
22
- detect_memory_leak_command = Groonga::QueryLog::Command::DetectMemoryLeak.new
22
+ detect_memory_leak_command = GroongaQueryLog::Command::DetectMemoryLeak.new
23
23
  exit(detect_memory_leak_command.run(ARGV))
@@ -17,7 +17,7 @@
17
17
  # License along with this library; if not, write to the Free Software
18
18
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
19
 
20
- require "groonga/query-log/command/extract"
20
+ require "groonga-query-log/command/extract"
21
21
 
22
- extract = Groonga::QueryLog::Command::Extract.new
22
+ extract = GroongaQueryLog::Command::Extract.new
23
23
  exit(extract.run(ARGV))
@@ -16,7 +16,7 @@
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
- command = Groonga::QueryLog::Command::FormatRegressionTestLogs.new
21
+ command = GroongaQueryLog::Command::FormatRegressionTestLogs.new
22
22
  exit(command.run(ARGV))
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
  #
4
- # Copyright (C) 2013-2014 Kouhei Sutou <kou@clear-code.com>
4
+ # Copyright (C) 2013-2017 Kouhei Sutou <kou@clear-code.com>
5
5
  #
6
6
  # This library is free software; you can redistribute it and/or
7
7
  # modify it under the terms of the GNU Lesser General Public
@@ -17,9 +17,7 @@
17
17
  # License along with this library; if not, write to the Free Software
18
18
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
 
20
- require "groonga/query-log/command/replay"
20
+ require "groonga-query-log/command/replay"
21
21
 
22
- Thread.abort_on_exception = true
23
-
24
- replay_command = Groonga::QueryLog::Command::Replay.new
22
+ replay_command = GroongaQueryLog::Command::Replay.new
25
23
  exit(replay_command.run(ARGV))
@@ -17,7 +17,7 @@
17
17
  # License along with this library; if not, write to the Free Software
18
18
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
 
20
- require "groonga/query-log/command/run-regression-test"
20
+ require "groonga-query-log/command/run-regression-test"
21
21
 
22
- command = Groonga::QueryLog::Command::RunRegressionTest.new
22
+ command = GroongaQueryLog::Command::RunRegressionTest.new
23
23
  exit(command.run(ARGV))
@@ -17,7 +17,7 @@
17
17
  # License along with this library; if not, write to the Free Software
18
18
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
 
20
- require "groonga/query-log/command/show-running-queries"
20
+ require "groonga-query-log/command/show-running-queries"
21
21
 
22
- command = Groonga::QueryLog::Command::ShowRunningQueries.new
22
+ command = GroongaQueryLog::Command::ShowRunningQueries.new
23
23
  exit(command.run(ARGV))
@@ -17,7 +17,7 @@
17
17
  # License along with this library; if not, write to the Free Software
18
18
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
 
20
- require "groonga/query-log/command/verify-server"
20
+ require "groonga-query-log/command/verify-server"
21
21
 
22
- verify_server_command = Groonga::QueryLog::Command::VerifyServer.new
22
+ verify_server_command = GroongaQueryLog::Command::VerifyServer.new
23
23
  exit(verify_server_command.run(ARGV))
data/doc/text/news.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # News
2
2
 
3
+ ## 1.2.9: 2018-02-04
4
+
5
+ ### Improvements
6
+
7
+ * `GroongaQueryLog`: Renamed from
8
+ `Groonga::QueryLog`. `Groonga::QueryLog` is deprecated but still
9
+ usable.
10
+
11
+ * `GroongaQueryLog::Analyzer::Statistic#each_operation`: Added
12
+ enumerator support.
13
+
14
+ * `groonga-query-log-analyze`: Added "N records" support in HTML report.
15
+
16
+ * `groonga-query-log-replay`: Changed the default protocol to HTTP
17
+ from GQTP.
18
+
19
+ * `groonga-query-log-analyze`: Added `--stream-all` option.
20
+
21
+ * `GroongaQueryLog::Parser`: Added extra information support in
22
+ `load` and `delete` commands' query log.
23
+
24
+ * `groonga-query-log-analyze-load`: Added.
25
+
26
+ * `groonga-query-log-analyze`: Added CSV reporter.
27
+
28
+ * `groonga-query-log-check-crash`: Added.
29
+
30
+ * `GroongaQueryLog::Parser#current_path`: Added.
31
+
32
+ * Required groonga-log 0.1.2 or later.
33
+
3
34
  ## 1.2.8: 2017-10-26
4
35
 
5
36
  ### Fixes
@@ -1,6 +1,6 @@
1
- # -*- mode: ruby; coding: utf-8 -*-
1
+ # -*- ruby -*-
2
2
  #
3
- # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2012-2018 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -20,7 +20,7 @@ base_dir = File.dirname(__FILE__)
20
20
  lib_dir = File.join(base_dir, "lib")
21
21
 
22
22
  $LOAD_PATH.unshift(lib_dir)
23
- require "groonga/query-log/version"
23
+ require "groonga-query-log/version"
24
24
 
25
25
  clean_white_space = lambda do |entry|
26
26
  entry.gsub(/(\A\n+|\n+\z)/, '') + "\n"
@@ -28,7 +28,7 @@ end
28
28
 
29
29
  Gem::Specification.new do |spec|
30
30
  spec.name = "groonga-query-log"
31
- spec.version = Groonga::QueryLog::VERSION.dup
31
+ spec.version = GroongaQueryLog::VERSION.dup
32
32
 
33
33
  spec.authors = ["Kouhei Sutou"]
34
34
  spec.email = ["kou@clear-code.com"]
@@ -54,6 +54,7 @@ Gem::Specification.new do |spec|
54
54
 
55
55
  spec.add_runtime_dependency("groonga-command-parser")
56
56
  spec.add_runtime_dependency("groonga-client")
57
+ spec.add_runtime_dependency("groonga-log", ">= 0.1.2")
57
58
 
58
59
  spec.add_development_dependency("test-unit")
59
60
  spec.add_development_dependency("test-unit-notify")
@@ -0,0 +1,42 @@
1
+ # Copyright (C) 2012-2018 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 "groonga-log"
18
+
19
+ require "groonga-query-log/version"
20
+ require "groonga-query-log/parser"
21
+ require "groonga-query-log/replayer"
22
+ require "groonga-query-log/server-verifier"
23
+ require "groonga-query-log/command-version-compatibility-checker"
24
+
25
+ module GroongaQueryLog
26
+ module AnalyzerNamespaceBackwardCompatibility
27
+ def const_missing(name)
28
+ case name
29
+ when :Analyzer
30
+ warn("GroongaQueryLog::Analyzer is deprecated. " +
31
+ "Use GroongaQueryLog::Command::Analyzer instead:\n" +
32
+ caller.join("\n"))
33
+ require "groonga-query-log/command/analyzer"
34
+ const_set(name, Command::Analyzer)
35
+ else
36
+ super
37
+ end
38
+ end
39
+ end
40
+
41
+ extend AnalyzerNamespaceBackwardCompatibility
42
+ end
@@ -1,6 +1,5 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
1
  # Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
2
+ # Copyright (C) 2017-2018 Kouhei Sutou <kou@clear-code.com>
4
3
  #
5
4
  # This library is free software; you can redistribute it and/or
6
5
  # modify it under the terms of the GNU Lesser General Public
@@ -15,20 +14,33 @@
15
14
  # License along with this library; if not, write to the Free Software
16
15
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
16
 
18
- module Groonga
19
- module QueryLog
20
- module CommandLineUtils
21
- def log_via_stdin?
22
- stdin_with_pipe? or stdin_with_redirect?
23
- end
17
+ module GroongaQueryLog
18
+ class CommandLine
19
+ class Error < StandardError
20
+ end
24
21
 
25
- def stdin_with_pipe?
26
- File.pipe?($stdin)
27
- end
22
+ class NoInputError < Error
23
+ end
28
24
 
29
- def stdin_with_redirect?
30
- not File.select([$stdin], [], [], 0).nil?
25
+ private
26
+ def parse_log(parser, log_paths, &process_statistic)
27
+ if log_paths.empty?
28
+ if stdin_with_pipe? or stdin_with_redirect?
29
+ parser.parse($stdin, &process_statistic)
30
+ else
31
+ raise NoInputError, "Error: Please specify input log files."
32
+ end
33
+ else
34
+ parser.parse_paths(log_paths, &process_statistic)
31
35
  end
32
36
  end
37
+
38
+ def stdin_with_pipe?
39
+ File.pipe?($stdin)
40
+ end
41
+
42
+ def stdin_with_redirect?
43
+ not File.select([$stdin], [], [], 0).nil?
44
+ end
33
45
  end
34
46
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2014-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,10 +14,9 @@
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 "groonga/query-log/incompatibility-detector"
17
+ require "groonga-query-log/incompatibility-detector"
18
18
 
19
- module Groonga
20
- module QueryLog
19
+ module GroongaQueryLog
21
20
  class CommandVersionCompatibilityChecker
22
21
  def initialize(options)
23
22
  @options = options
@@ -96,5 +95,4 @@ module Groonga
96
95
  end
97
96
  end
98
97
  end
99
- end
100
98
  end
@@ -0,0 +1,188 @@
1
+ # Copyright (C) 2017-2018 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
+
19
+ require "groonga-query-log"
20
+ require "groonga-query-log/command-line"
21
+
22
+ module GroongaQueryLog
23
+ module Command
24
+ class AnalyzeLoad < CommandLine
25
+ def initialize
26
+ setup_options
27
+ @pending_entry = nil
28
+ end
29
+
30
+ # Executes load command analyzer for Groonga's query logs.
31
+ # "groonga-query-log-analyze-load" command run this method.
32
+ #
33
+ # @example
34
+ # analyze_load = GroongaQueryLog::Command::AnalyzeLoad.new
35
+ # analyze_load.run("--output", "statistics.csv",
36
+ # "query.log")
37
+ #
38
+ # If only paths of query log files are specified,
39
+ # this method prints a result of them to console.
40
+ #
41
+ # @param [Array<String>] arguments arguments for
42
+ # groonga-query-log-analyze-load. Please execute
43
+ # `groonga-query-log-analyze-load --help` or see
44
+ # #setup_options.
45
+ def run(arguments)
46
+ begin
47
+ log_paths = @option_parser.parse!(arguments)
48
+ rescue OptionParser::InvalidOption => error
49
+ $stderr.puts(error)
50
+ return false
51
+ end
52
+
53
+ begin
54
+ open_output do |output|
55
+ report_header(output)
56
+ parse(log_paths) do |statistic|
57
+ report_statistic(output, statistic)
58
+ end
59
+ if @pending_entry
60
+ report_entry(output, @pending_entry)
61
+ @pending_entry = nil
62
+ end
63
+ end
64
+ rescue Interrupt
65
+ rescue Error
66
+ $stderr.puts($!.message)
67
+ return false
68
+ end
69
+
70
+ true
71
+ end
72
+
73
+ private
74
+ def setup_options
75
+ @options = {}
76
+ @options[:output] = "-"
77
+ @options[:target_commands] = ["select", "load"]
78
+
79
+ @option_parser = OptionParser.new do |parser|
80
+ parser.version = VERSION
81
+ parser.banner += " LOG1 ..."
82
+
83
+ parser.on("--output=PATH",
84
+ "Output to PATH.",
85
+ "'-' PATH means standard output.",
86
+ "(#{@options[:output]})") do |output|
87
+ @options[:output] = output
88
+ end
89
+ end
90
+ end
91
+
92
+ def open_output
93
+ if @options[:output] == "-"
94
+ yield($stdout)
95
+ else
96
+ File.open(@options[:output], "w") do |output|
97
+ yield(output)
98
+ end
99
+ end
100
+ end
101
+
102
+ def parse(log_paths, &process_statistic)
103
+ parser = Parser.new(@options)
104
+ parse_log(parser, log_paths, &process_statistic)
105
+ end
106
+
107
+ def report_statistic(output, statistic)
108
+ command = statistic.command
109
+ if command.name == "select"
110
+ process_select_statistic(output, statistic, command)
111
+ else
112
+ process_load_statistic(output, statistic, command)
113
+ end
114
+ end
115
+
116
+ def process_select_statistic(output, statistic, select_command)
117
+ return if @pending_entry.nil?
118
+
119
+ operations = statistic.operations
120
+ if operations.any? {|operation| operation[:name] == "filter"}
121
+ return
122
+ end
123
+ select_operation = operations.find do |operation|
124
+ operation[:name] == "select"
125
+ end
126
+ return if select_operation.nil?
127
+
128
+ return if @pending_entry[2] != select_command[:table]
129
+
130
+ @pending_entry[6] = select_operation[:n_records]
131
+ report_entry(output, @pending_entry)
132
+ @pending_entry = nil
133
+ end
134
+
135
+ def process_load_statistic(output, statistic, load_command)
136
+ operation = statistic.operations.first
137
+ if operation and operation[:extra]
138
+ extra = operation[:extra]
139
+ extra_counts = extra.scan(/\[(\d+)\]/).flatten.collect(&:to_i)
140
+ n_loaded_records = operation[:n_records]
141
+ n_record_errors = extra_counts[0]
142
+ n_column_errors = extra_counts[1]
143
+ total = extra_counts[2]
144
+ else
145
+ n_loaded_records = nil
146
+ n_record_errors = nil
147
+ n_column_errors = nil
148
+ total = nil
149
+ end
150
+ entry = [
151
+ statistic.start_time.iso8601,
152
+ statistic.elapsed_in_seconds,
153
+ load_command.table,
154
+ n_loaded_records,
155
+ n_record_errors,
156
+ n_column_errors,
157
+ total,
158
+ ]
159
+ if @pending_entry
160
+ report_entry(output, @pending_entry)
161
+ @pending_entry = nil
162
+ end
163
+ if total.nil?
164
+ @pending_entry = entry
165
+ else
166
+ report_entry(output, entry)
167
+ end
168
+ end
169
+
170
+ def report_header(output)
171
+ header = [
172
+ "start_time",
173
+ "elapsed",
174
+ "table",
175
+ "n_loaded_records",
176
+ "n_record_errors",
177
+ "n_column_errors",
178
+ "n_total_records",
179
+ ]
180
+ output.puts(header.join(","))
181
+ end
182
+
183
+ def report_entry(output, entry)
184
+ output.puts(entry.join(","))
185
+ end
186
+ end
187
+ end
188
+ end