Class: LogParser::LogEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/production_log/parser.rb

Overview

LogEntry contains a summary of log data for a single request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry) ⇒ LogEntry

Creates a new LogEntry from the log data in entry.



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/production_log/parser.rb', line 56

def initialize(entry)
  @page = nil
  @ip = nil
  @time = nil
  @queries = []
  @request_time = 0
  @render_time = 0
  @db_time = 0
  @in_component = 0

  parse entry
end

Instance Attribute Details

#db_timeObject (readonly)

Total database time



51
52
53
# File 'lib/production_log/parser.rb', line 51

def db_time
  @db_time
end

#ipObject (readonly)

Requesting IP



25
26
27
# File 'lib/production_log/parser.rb', line 25

def ip
  @ip
end

#pageObject (readonly)

Controller and action for this request



20
21
22
# File 'lib/production_log/parser.rb', line 20

def page
  @page
end

#queriesObject (readonly)

Array of SQL queries containing query type and time taken. The complete text of the SQL query is not saved to reduct memory usage.



36
37
38
# File 'lib/production_log/parser.rb', line 36

def queries
  @queries
end

#render_timeObject (readonly)

Total render time.



46
47
48
# File 'lib/production_log/parser.rb', line 46

def render_time
  @render_time
end

#request_timeObject (readonly)

Total request time, including database, render and other.



41
42
43
# File 'lib/production_log/parser.rb', line 41

def request_time
  @request_time
end

#timeObject (readonly)

Time the request was made



30
31
32
# File 'lib/production_log/parser.rb', line 30

def time
  @time
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



107
108
109
110
111
112
113
114
115
116
# File 'lib/production_log/parser.rb', line 107

def ==(other) # :nodoc:
  other.class == self.class and
  other.page == self.page and
  other.ip == self.ip and
  other.time == self.time and
  other.queries == self.queries and
  other.request_time == self.request_time and
  other.render_time == self.render_time and
  other.db_time == self.db_time
end

#parse(entry) ⇒ Object

Extracts log data from entry, which is an Array of lines from the same request.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/production_log/parser.rb', line 73

def parse(entry)
  entry.each do |line|
    case line
    when /^Parameters/, /^Cookie set/, /^Rendering/,
      /^Redirected/ then
      # nothing
    when /^Processing ([\S]+) \(for (.+) at (.*)\)/ then
      next if @in_component > 0
      @page = $1
      @ip   = $2
      @time = $3
    when /^Completed in ([\S]+) .+ Rendering: ([\S]+) .+ DB: ([\S]+)/ then
      next if @in_component > 0
      @request_time = $1.to_f
      @render_time = $2.to_f
      @db_time = $3.to_f
    when /^Completed in ([\S]+) .+ DB: ([\S]+)/ then # Redirect
      next if @in_component > 0
      @request_time = $1.to_f
      @render_time = 0
      @db_time = $2.to_f
    when /(.+?) \(([^)]+)\)   / then
      @queries << [$1, $2.to_f]
    when /^Start rendering component / then
      @in_component += 1
    when /^End of component rendering$/ then
      @in_component -= 1
    when /^Fragment hit: / then
    else # noop
#          raise "Can't handle #{line.inspect}" if $TESTING
    end
  end
end