Kouhei Sutou
null+****@clear*****
Fri Dec 6 11:57:13 JST 2013
Kouhei Sutou 2013-12-06 11:57:13 +0900 (Fri, 06 Dec 2013) New Revision: a7a6b4421033faa1e1c126c3d29d37b9affd0277 https://github.com/groonga/groonga-query-log/commit/a7a6b4421033faa1e1c126c3d29d37b9affd0277 Message: Remove threshold from statistics Threshold should have parser. Becauase parser creates a new statistic. All new statistics should have correct threshold. New statistic creators should initialize threshold. Modified files: lib/groonga/query-log/analyzer.rb lib/groonga/query-log/analyzer/reporter.rb lib/groonga/query-log/analyzer/reporter/console.rb lib/groonga/query-log/analyzer/reporter/html.rb lib/groonga/query-log/analyzer/sized-statistics.rb lib/groonga/query-log/analyzer/statistic.rb lib/groonga/query-log/parser.rb Modified: lib/groonga/query-log/analyzer.rb (+2 -2) =================================================================== --- lib/groonga/query-log/analyzer.rb 2013-12-06 11:29:02 +0900 (d422001) +++ lib/groonga/query-log/analyzer.rb 2013-12-06 11:57:13 +0900 (3f7d452) @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2011-2012 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2011-2013 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 @@ -227,7 +227,7 @@ module Groonga end def parse(log_paths, &process_statistic) - parser = Groonga::QueryLog::Parser.new + parser = Groonga::QueryLog::Parser.new(@options) if log_paths.empty? unless log_via_stdin? raise(NoInputError, "Error: Please specify input log files.") Modified: lib/groonga/query-log/analyzer/reporter.rb (+10 -1) =================================================================== --- lib/groonga/query-log/analyzer/reporter.rb 2013-12-06 11:29:02 +0900 (dd12058) +++ lib/groonga/query-log/analyzer/reporter.rb 2013-12-06 11:57:13 +0900 (7134b0e) @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2011-2012 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2011-2013 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 @@ -24,10 +24,15 @@ module Groonga include Enumerable attr_reader :output + attr_accessor :slow_operation_threshold, :slow_response_threshold def initialize(statistics) @statistics = statistics @report_summary = true @output = $stdout + @slow_operation_threshold = + Statistic::DEFAULT_SLOW_OPERATION_THRESHOLD + @slow_response_threshold = + Statistic::DEFAULT_SLOW_RESPONSE_THRESHOLD end def apply_options(options) @@ -35,6 +40,10 @@ module Groonga unless options[:report_summary].nil? @report_summary = options[:report_summary] end + @slow_operation_threshold = + options[:slow_operation_threshold] || @slow_operation_threshold + @slow_response_threshold = + options[:slow_response_threshold] || @slow_response_threshold end def output=(output) Modified: lib/groonga/query-log/analyzer/reporter/console.rb (+3 -3) =================================================================== --- lib/groonga/query-log/analyzer/reporter/console.rb 2013-12-06 11:29:02 +0900 (601f89c) +++ lib/groonga/query-log/analyzer/reporter/console.rb 2013-12-06 11:57:13 +0900 (e65bf98) @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2011-2012 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2011-2013 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 @@ -169,8 +169,8 @@ module Groonga def report_summary write("Summary:\n") write(" Threshold:\n") - write(" slow response : #{@statistics.slow_response_threshold}\n") - write(" slow operation : #{@statistics.slow_operation_threshold}\n") + write(" slow response : #{@slow_response_threshold}\n") + write(" slow operation : #{@slow_operation_threshold}\n") write(" # of responses : #{@statistics.n_responses}\n") write(" # of slow responses : #{@statistics.n_slow_responses}\n") write(" responses/sec : #{@statistics.responses_per_second}\n") Modified: lib/groonga/query-log/analyzer/reporter/html.rb (+2 -2) =================================================================== --- lib/groonga/query-log/analyzer/reporter/html.rb 2013-12-06 11:29:02 +0900 (0258ed1) +++ lib/groonga/query-log/analyzer/reporter/html.rb 2013-12-06 11:57:13 +0900 (9dcdf52) @@ -189,11 +189,11 @@ td.name <tr><th>Name</th><th>Value</th></tr> <tr> <th>Slow response threshold</th> - <td><%= h(@statistics.slow_response_threshold) %>sec</td> + <td><%= h(@slow_response_threshold) %>sec</td> </tr> <tr> <th>Slow operation threshold</th> - <td><%= h(@statistics.slow_operation_threshold) %>sec</td> + <td><%= h(@slow_operation_threshold) %>sec</td> </tr> </table> </div> Modified: lib/groonga/query-log/analyzer/sized-statistics.rb (+0 -9) =================================================================== --- lib/groonga/query-log/analyzer/sized-statistics.rb 2013-12-06 11:29:02 +0900 (6cd68c1) +++ lib/groonga/query-log/analyzer/sized-statistics.rb 2013-12-06 11:57:13 +0900 (3af3494) @@ -29,12 +29,9 @@ module Groonga attr_reader :n_responses, :n_slow_responses, :n_slow_operations attr_reader :slow_operations, :total_elapsed attr_reader :start_time, :last_time - attr_accessor :slow_operation_threshold, :slow_response_threshold def initialize @max_size = 10 self.order = "-elapsed" - @slow_operation_threshold = 0.1 - @slow_response_threshold = 0.2 @start_time = nil @last_time = nil @n_responses = 0 @@ -53,10 +50,6 @@ module Groonga def apply_options(options) @max_size = options[:n_entries] || @max_size self.order = options[:order] || @order - @slow_operation_threshold = - options[:slow_operation_threshold] || @slow_operation_threshold - @slow_response_threshold = - options[:slow_response_threshold] || @slow_response_threshold unless options[:report_summary].nil? @collect_slow_statistics = options[:report_summary] end @@ -146,8 +139,6 @@ module Groonga end def update_statistic(statistic) - statistic.slow_response_threshold = @slow_response_threshold - statistic.slow_operation_threshold = @slow_operation_threshold @start_time ||= statistic.start_time @start_time = [@start_time, statistic.start_time].min @last_time ||= statistic.last_time Modified: lib/groonga/query-log/analyzer/statistic.rb (+5 -2) =================================================================== --- lib/groonga/query-log/analyzer/statistic.rb 2013-12-06 11:29:02 +0900 (297ad79) +++ lib/groonga/query-log/analyzer/statistic.rb 2013-12-06 11:57:13 +0900 (2e46f6a) @@ -22,6 +22,9 @@ module Groonga module QueryLog class Analyzer class Statistic + DEFAULT_SLOW_OPERATION_THRESHOLD = 0.1 + DEFAULT_SLOW_RESPONSE_THRESHOLD = 0.2 + attr_reader :context_id, :start_time, :raw_command attr_reader :elapsed, :return_code attr_accessor :slow_operation_threshold, :slow_response_threshold @@ -33,8 +36,8 @@ module Groonga @operations = [] @elapsed = nil @return_code = 0 - @slow_operation_threshold = 0.1 - @slow_response_threshold = 0.2 + @slow_operation_threshold = DEFAULT_SLOW_OPERATION_THRESHOLD + @slow_response_threshold = DEFAULT_SLOW_RESPONSE_THRESHOLD end def start(start_time, command) Modified: lib/groonga/query-log/parser.rb (+16 -2) =================================================================== --- lib/groonga/query-log/parser.rb 2013-12-06 11:29:02 +0900 (8ab27db) +++ lib/groonga/query-log/parser.rb 2013-12-06 11:57:13 +0900 (9d91f77) @@ -23,7 +23,10 @@ require "groonga/query-log/analyzer/statistic" module Groonga module QueryLog class Parser - def initialize + def initialize(options={}) + @options = options + @slow_operation_threshold = options[:slow_operation_threshold] + @slow_response_threshold = options[:slow_response_threshold] end # Parses query-log file as stream to @@ -59,7 +62,7 @@ module Groonga time_stamp, context_id, type, rest, &block) case type when ">" - statistic = Analyzer::Statistic.new(context_id) + statistic = create_statistic(context_id) statistic.start(time_stamp, rest) current_statistics[context_id] = statistic when ":" @@ -82,6 +85,17 @@ module Groonga block.call(statistic) end end + + def create_statistic(context_id) + statistic = Analyzer::Statistic.new(context_id) + if @slow_operation_threshold + statistic.slow_operation_threshold = @slow_operation_threshold + end + if @slow_response_threshold + statistic.slow_response_threshold = @slow_response_threshold + end + statistic + end end end end -------------- next part -------------- HTML����������������������������...Download