class GroongaQueryLog::Command::Analyzer::ConsoleReporter
Public Class Methods
new(statistics, options)
click to toggle source
Calls superclass method
GroongaQueryLog::Command::Analyzer::Reporter::new
# File lib/groonga-query-log/command/analyzer/reporter/console.rb, line 125 def initialize(statistics, options) super @color = @options[:color] @color = :auto if @color.nil? @reset_color = Color.new("reset") @color_schema = { :elapsed => {:foreground => :white, :background => :green}, :time => {:foreground => :white, :background => :cyan}, :slow => {:foreground => :white, :background => :red}, } end
Public Instance Methods
finish()
click to toggle source
# File lib/groonga-query-log/command/analyzer/reporter/console.rb, line 159 def finish end
report_statistic(statistic)
click to toggle source
# File lib/groonga-query-log/command/analyzer/reporter/console.rb, line 143 def report_statistic(statistic) @index += 1 write("%*d) %s\n" % [@digit, @index, format_heading(statistic)]) report_parameters(statistic) report_operations(statistic) end
report_statistics()
click to toggle source
Calls superclass method
GroongaQueryLog::Command::Analyzer::Reporter#report_statistics
# File lib/groonga-query-log/command/analyzer/reporter/console.rb, line 137 def report_statistics write("\n") write("Slow Queries:\n") super end
start()
click to toggle source
# File lib/groonga-query-log/command/analyzer/reporter/console.rb, line 150 def start @index = 0 if @statistics.size.zero? @digit = 1 else @digit = Math.log10(@statistics.size).truncate + 1 end end
Private Instance Methods
colorize(text, schema_name)
click to toggle source
# File lib/groonga-query-log/command/analyzer/reporter/console.rb, line 295 def colorize(text, schema_name) return text unless @color options = @color_schema[schema_name] color = Color.new("none") if options[:foreground] color += Color.new(options[:foreground].to_s, :bold => true) end if options[:background] color += Color.new(options[:background].to_s, :foreground => false) end "%s%s%s" % [color.escape_sequence, text, @reset_color.escape_sequence] end
format_heading(statistic)
click to toggle source
# File lib/groonga-query-log/command/analyzer/reporter/console.rb, line 274 def format_heading(statistic) formatted_elapsed = colorize("%8.8f" % statistic.elapsed_in_seconds, :elapsed) data = [ format_time(statistic.start_time), format_time(statistic.end_time), formatted_elapsed, statistic.return_code, ] if @report_command_line data << statistic.raw_command else data << statistic.command.name end "[%s-%s (%s)](%d): %s" % data end
format_time(time)
click to toggle source
Calls superclass method
GroongaQueryLog::Command::Analyzer::Reporter#format_time
# File lib/groonga-query-log/command/analyzer/reporter/console.rb, line 291 def format_time(time) colorize(super, :time) end
guess_color_availability(output)
click to toggle source
# File lib/groonga-query-log/command/analyzer/reporter/console.rb, line 255 def guess_color_availability(output) return false unless output.tty? case ENV["TERM"] when /term(?:-(?:256)?color)?\z/, "screen" true else return true if ENV["EMACS"] == "t" false end end
report_operations(statistic)
click to toggle source
# File lib/groonga-query-log/command/analyzer/reporter/console.rb, line 230 def report_operations(statistic) statistic.each_operation do |operation| relative_elapsed_in_seconds = operation[:relative_elapsed_in_seconds] formatted_elapsed = "%8.8f" % relative_elapsed_in_seconds if operation[:slow?] formatted_elapsed = colorize(formatted_elapsed, :slow) end operation_report = " %2d) %s: %10s" % [operation[:i] + 1, formatted_elapsed, operation[:name]] if operation[:n_records] operation_report << "(%6d)" % operation[:n_records] else operation_report << "(%6s)" % "" end context = operation[:context] if context context = colorize(context, :slow) if operation[:slow?] operation_report << " " << context end write("#{operation_report}\n") end write("\n") end
report_parameters(statistic)
click to toggle source
# File lib/groonga-query-log/command/analyzer/reporter/console.rb, line 221 def report_parameters(statistic) command = statistic.command write(" name: <#{command.command_name}>\n") write(" parameters:\n") command.arguments.each do |key, value| write(" <#{key}>: <#{value}>\n") end end
report_slow_operations()
click to toggle source
# File lib/groonga-query-log/command/analyzer/reporter/console.rb, line 198 def report_slow_operations write(" Slow Operations:\n") total_elapsed_digit = nil total_elapsed_decimal_digit = 6 n_operations_digit = nil @statistics.each_slow_operation do |grouped_operation| total_elapsed = grouped_operation[:total_elapsed] total_elapsed_digit ||= Math.log10(total_elapsed).truncate + 1 n_operations = grouped_operation[:n_operations] n_operations_digit ||= Math.log10(n_operations).truncate + 1 parameters = [total_elapsed_digit + 1 + total_elapsed_decimal_digit, total_elapsed_decimal_digit, total_elapsed, grouped_operation[:total_elapsed_ratio], n_operations_digit, n_operations, grouped_operation[:n_operations_ratio], grouped_operation[:name], grouped_operation[:context]] write(" [%*.*f](%5.2f%%) [%*d](%5.2f%%) %9s: %s\n" % parameters) end end
report_summary()
click to toggle source
# File lib/groonga-query-log/command/analyzer/reporter/console.rb, line 171 def report_summary write("Summary:\n") write(" 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") write(" start time : #{format_time(@statistics.start_time)}\n") write(" end time : #{format_time(@statistics.end_time)}\n") write(" period(sec) : %.3f\n" % @statistics.period) slow_response_ratio = @statistics.slow_response_ratio write(" slow response ratio : %5.3f%%\n" % slow_response_ratio) write(" total response time : %.3f\n" % @statistics.total_elapsed) write(" Workers:\n") @statistics.each_worker do |worker| write(" #{worker.id}:\n") write(" # of processed requests: #{worker.n_statistics}\n") write(" idle time(sec):\n") write(" total : %.3f\n" % worker.idle_time_total) write(" mean : %.3f\n" % worker.idle_time_mean) write(" min : %.3f\n" % worker.idle_time_min) write(" max : %.3f\n" % worker.idle_time_max) end report_slow_operations end
setup() { || ... }
click to toggle source
Calls superclass method
GroongaQueryLog::Command::Analyzer::Reporter#setup
# File lib/groonga-query-log/command/analyzer/reporter/console.rb, line 163 def setup super do setup_color do yield end end end
setup_color() { || ... }
click to toggle source
# File lib/groonga-query-log/command/analyzer/reporter/console.rb, line 266 def setup_color color = @color @color = guess_color_availability(@output) if @color == :auto yield ensure @color = color end