Kouhei Sutou
null+****@clear*****
Tue Jan 9 11:42:38 JST 2018
Kouhei Sutou 2018-01-09 11:42:38 +0900 (Tue, 09 Jan 2018) New Revision: 571cd3db75e1194e548fa1770d25098acff2f427 https://github.com/groonga/groonga-query-log/commit/571cd3db75e1194e548fa1770d25098acff2f427 Message: groonga-query-log-analyzer: add CSV reporter Added files: lib/groonga-query-log/command/analyzer/reporter/csv.rb Modified files: lib/groonga-query-log/command/analyzer.rb Modified: lib/groonga-query-log/command/analyzer.rb (+13 -4) =================================================================== --- lib/groonga-query-log/command/analyzer.rb 2017-12-13 10:08:58 +0900 (2a143c8) +++ lib/groonga-query-log/command/analyzer.rb 2018-01-09 11:42:38 +0900 (3eda29d) @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2017 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2011-2018 Kouhei Sutou <kou �� clear-code.com> # Copyright (C) 2012 Haruka Yoshihara <yoshihara �� clear-code.com> # # This library is free software; you can redistribute it and/or @@ -23,6 +23,7 @@ require "groonga-query-log/command-line-utils" require "groonga-query-log/command/analyzer/streamer" require "groonga-query-log/command/analyzer/sized-statistics" require "groonga-query-log/command/analyzer/reporter/console" +require "groonga-query-log/command/analyzer/reporter/csv" require "groonga-query-log/command/analyzer/reporter/html" require "groonga-query-log/command/analyzer/reporter/json" require "groonga-query-log/command/analyzer/reporter/json-stream" @@ -206,7 +207,13 @@ module GroongaQueryLog @options[:target_tables] = tables end - available_reporters = ["console", "json", "json-stream", "html"] + available_reporters = [ + "console", + "csv", + "html", + "json", + "json-stream", + ] parser.on("--reporter=REPORTER", available_reporters, "Reports statistics by REPORTER.", @@ -247,12 +254,14 @@ module GroongaQueryLog def create_reporter(statistics) case @options[:reporter] + when "csv" + CSVReporter.new(statistics) + when "html" + HTMLReporter.new(statistics) when "json" JSONReporter.new(statistics) when "json-stream" JSONStreamReporter.new(statistics) - when "html" - HTMLReporter.new(statistics) else ConsoleReporter.new(statistics) end Added: lib/groonga-query-log/command/analyzer/reporter/csv.rb (+60 -0) 100644 =================================================================== --- /dev/null +++ lib/groonga-query-log/command/analyzer/reporter/csv.rb 2018-01-09 11:42:38 +0900 (b664add) @@ -0,0 +1,60 @@ +# Copyright (C) 2018 Kouhei Sutou <kou �� clear-code.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +require "csv" +require "time" + +require "groonga-query-log/command/analyzer/reporter" + +module GroongaQueryLog + module Command + class Analyzer + class CSVReporter < Reporter + def start + @csv = CSV.new(@output) + @csv << [ + "start_time", + "last_time", + "elapsed", + "return_code", + "slow", + "command_name", + "command_line", + ] + end + + def report_statistic(statistic) + @csv << [ + statistic.start_time.iso8601, + statistic.last_time.iso8601, + statistic.elapsed_in_seconds, + statistic.return_code, + statistic.slow?, + statistic.command.name, + statistic.raw_command, + ] + end + + def finish + @csv.close + end + + def report_summary + end + end + end + end +end -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180109/3d986293/attachment-0001.htm