Sha256: 5a22e48a253ddfd99397449f14c20bb89d9ea4f665c06d98f23531c699a83209
Contents?: true
Size: 1.87 KB
Versions: 4
Compression:
Stored size: 1.87 KB
Contents
require File.join(File.dirname(__FILE__), 'slow_actions_log_entry') class SlowActions private class Parser def initialize(file_path) @file_path = file_path raise "File not found: #{file_path}" unless File.exists? file_path @file = File.new(file_path, 'r') end def parse @log_entries = [] begin while true line = @file.readline if line =~ /^Processing/ @log_entries << parse_log_entry(line) end end rescue EOFError => ex @file.close end return @log_entries end private def parse_log_entry(line) la = LogEntry.new if line =~ /^Processing (\S+)#(\S+) \(for (\S+) at (\S+) (\S+)\) \[(\S+)\]$/ la.controller = $1 la.action = $2 la.ip = $3 la.date = $4 la.time = $5 la.method = $6 end line = @file.readline if line =~ /^\s+Session ID: (\S+)$/ la.session = $1 end line = @file.readline if line =~ /^\s+Parameters: (.*)$/ la.parameters = $1 end line = @file.readline if line == "\n" error_text = parse_error la.error_text = error_text return la end while !(line =~ /^Completed/ and line != "\n") line = @file.readline end if line =~ /^Completed in (\S+)/ la.duration = $1.to_f end if line =~ /Rendering: (\S+)/ la.rendering = $1.to_f else la.rendering = 0.0 end if line =~ /DB: (\S+)/ la.db = $1.to_f else la.db = 0.0 end return la end def parse_error line = "\n" while line == "\n" line = @file.readline end error_txt = "" while line != "\n" line = @file.readline error_txt += line end return error_txt end end end
Version data entries
4 entries across 4 versions & 1 rubygems