Kouhei Sutou
null+****@clear*****
Mon Jun 23 17:59:55 JST 2014
Kouhei Sutou 2014-06-23 17:59:55 +0900 (Mon, 23 Jun 2014) New Revision: 8b854833aa6aaef5b4351d0299b97955ed84a7f6 https://github.com/groonga/groonga-query-log/commit/8b854833aa6aaef5b4351d0299b97955ed84a7f6 Message: Add groonga-query-log-show-running-queries command It is useful for detecting crash query by passing crash time and query log. You can get running queries on crash. One of them will be a query that causes crash. Added files: bin/groonga-query-log-show-running-queries lib/groonga/query-log/command/show-running-queries.rb Added: bin/groonga-query-log-show-running-queries (+23 -0) 100755 =================================================================== --- /dev/null +++ bin/groonga-query-log-show-running-queries 2014-06-23 17:59:55 +0900 (09820cc) @@ -0,0 +1,23 @@ +#!/usr/bin/env ruby +# -*- coding: utf-8 -*- +# +# Copyright (C) 2014 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 "groonga/query-log/command/show-running-queries" + +command = Groonga::QueryLog::Command::ShowRunningQueries.new +exit(command.run(ARGV)) Added: lib/groonga/query-log/command/show-running-queries.rb (+80 -0) 100644 =================================================================== --- /dev/null +++ lib/groonga/query-log/command/show-running-queries.rb 2014-06-23 17:59:55 +0900 (9625576) @@ -0,0 +1,80 @@ +# Copyright (C) 2014 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 "optparse" +require "time" + +require "groonga/query-log/version" +require "groonga/query-log/parser" + +module Groonga + module QueryLog + module Command + class ShowRunningQueries + def initialize + @timestamp = nil + end + + def run(command_line) + input_paths = create_parser.parse(command_line) + each_parsing_statistic(input_paths) do |statistic| + timestamp = statistic.start_time.strftime("%Y-%m-%d %H:%M:%S.%6N") + puts("#{timestamp}:#{statistic.raw_command}") + end + true + end + + private + def create_parser + parser = OptionParser.new + parser.version = VERSION + parser.banner += " QUERY_LOG" + + parser.separator("") + parser.separator("Options:") + + parser.on("--base-time=TIME", + "Show running queries at TIME", + "You can use popular time format for TIME such as W3C-DTF", + "(now)") do |timestamp| + @timestamp = Time.parse(timestamp) + end + end + + def each_parsing_statistic(input_paths) + parser = Parser.new + catch do |tag| + input_paths.each do |input_path| + File.open(input_path) do |input| + parser.parse(input) do |statistic| + next if****@times*****? + next if statistic.start_time < @timestamp + if statistic.start_time == @timestamp + yield(statistic) + end + throw(tag) + end + end + end + end + parser.parsing_statistics.each do |statistic| + yield(statistic) + end + end + end + end + end +end -------------- next part -------------- HTML����������������������������... Télécharger