Class: GroongaQueryLog::Command::CheckCrash::Checker

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga-query-log/command/check-crash.rb

Instance Method Summary collapse

Constructor Details

#initialize(log_paths) ⇒ Checker

Returns a new instance of Checker.



112
113
114
# File 'lib/groonga-query-log/command/check-crash.rb', line 112

def initialize(log_paths)
  split_log_paths(log_paths)
end

Instance Method Details

#checkObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/groonga-query-log/command/check-crash.rb', line 116

def check
  processes = ProcessEnumerator.new(@general_log_paths)
  processes.each do |process|
    need_query_log_parsing = true
    if process.successfully_finished?
      need_query_log_parsing = false
      p [:process,
         :success,
         process.start_time.iso8601,
         process.last_time.iso8601,
         process.pid,
         process.start_log_path,
         process.last_log_path]
    elsif process.crashed?
      p [:process,
         :crashed,
         process.start_time.iso8601,
         process.last_time.iso8601,
         process.pid,
         process.start_log_path,
         process.last_log_path]
    else
      p [:process,
         :unfinished,
         process.start_time.iso8601,
         process.pid,
         process.start_log_path]
    end

    unless process.n_leaks.zero?
      p [:leak,
         process.n_leaks,
         process.last_time.iso8601,
         process.pid,
         process.last_log_path]
    end

    unless process.important_entries.empty?
      puts("Important entries:")
      process.important_entries.each_with_index do |entry, i|
        puts("#{entry.timestamp.iso8601}: " +
             "#{entry.log_level}: " +
             "#{entry.message}")
      end
    end

    next unless need_query_log_parsing

    start = process.start_time
    last = process.last_time
    @flushed = nil
    @unflushed_statistics = []
    query_log_parser = Parser.new
    query_log_parser.parse_paths(@query_log_paths) do |statistic|
      next if statistic.start_time < start
      break if statistic.start_time > last
      check_query_log_statistic(query_log_parser.current_path,
                                statistic)
    end
    parsing_statistics = query_log_parser.parsing_statistics
    target_parsing_statistics = parsing_statistics.reject do |statistic|
      statistic.start_time < start
    end
    unless target_parsing_statistics.empty?
      puts("Running queries:")
      target_parsing_statistics.each do |statistic|
        puts("#{statistic.start_time.iso8601}:")
        puts(statistic.command.to_command_format(pretty_print: true))
      end
    end
    unless @unflushed_statistics.empty?
      puts("Unflushed commands in #{start.iso8601}/#{last.iso8601}")
      @unflushed_statistics.each do |statistic|
        puts("#{statistic.start_time.iso8601}: #{statistic.raw_command}")
      end
    end
  end
end