From 86c59e01aa61c3c195c0424dd3e128dfcdad0420 Mon Sep 17 00:00:00 2001 From: Michel Barbosa Date: Thu, 7 Jan 2010 22:56:04 +0100 Subject: [PATCH] moved HODEL_LOG_FORMAT_REGEX to Oink::Base class and skip non Hodel 3000 compliant lines from both the MemoryUsageReporter and ActiveRecordInstantiationReporter classes --- lib/oink/active_record_instantiation_reporter.rb | 5 ++++- lib/oink/base.rb | 1 + lib/oink/memory_usage_reporter.rb | 6 ++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/oink/active_record_instantiation_reporter.rb b/lib/oink/active_record_instantiation_reporter.rb index d804ff6..4ab86f7 100644 --- a/lib/oink/active_record_instantiation_reporter.rb +++ b/lib/oink/active_record_instantiation_reporter.rb @@ -16,6 +16,9 @@ def print(output) @inputs.each do |input| input.each_line do |line| line = line.strip + + # Skip this line since we're only interested in the Hodel 3000 compliant lines + next unless line =~ HODEL_LOG_FORMAT_REGEX if line =~ /rails\[(\d+)\]/ pid = $1 @@ -40,7 +43,7 @@ def print(output) if @pids[pid][:ar_count] > @threshold @bad_actions[@pids[pid][:action]] ||= 0 @bad_actions[@pids[pid][:action]] = @bad_actions[@pids[pid][:action]] + 1 - date = /^(\w+ \d{2} \d{2}:\d{2}:\d{2})/.match(line).captures[0] + date = HODEL_LOG_FORMAT_REGEX.match(line).captures[0] @bad_requests.push(OinkedARRequest.new(@pids[pid][:action], date, @pids[pid][:buffer], @pids[pid][:ar_count])) if @format == :verbose @pids[pid][:buffer].each { |b| output.puts b } diff --git a/lib/oink/base.rb b/lib/oink/base.rb index c6245b3..9506b7f 100644 --- a/lib/oink/base.rb +++ b/lib/oink/base.rb @@ -5,6 +5,7 @@ class Base VERSION = '0.1.0' FORMATS = %w[verbose short-summary summary] FORMAT_ALIASES = { "v" => "verbose", "ss" => "short-summary", "s" => "summary" } + HODEL_LOG_FORMAT_REGEX = /^(\w+ \d{2} \d{2}:\d{2}:\d{2})/ def initialize(input, threshold, options = {}) @inputs = Array(input) diff --git a/lib/oink/memory_usage_reporter.rb b/lib/oink/memory_usage_reporter.rb index c11f7a2..7461c97 100644 --- a/lib/oink/memory_usage_reporter.rb +++ b/lib/oink/memory_usage_reporter.rb @@ -6,8 +6,6 @@ module Oink class MemoryUsageReporter < Base - HODEL_LOG_FORMAT_REGEX = /^(\w+ \d{2} \d{2}:\d{2}:\d{2})/ - def print(output) output.puts "---- MEMORY THRESHOLD ----" output.puts "THRESHOLD: #{@threshold/1024} MB\n" @@ -16,10 +14,10 @@ def print(output) @inputs.each do |input| input.each_line do |line| + line = line.strip + # Skip this line since we're only interested in the Hodel 3000 compliant lines next unless line =~ HODEL_LOG_FORMAT_REGEX - - line = line.strip if line =~ /rails\[(\d+)\]/ pid = $1