erkki-production_log_analyzer 2009022402 → 2009022403

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'hoe'
3
3
  $:.unshift './lib'
4
4
  require 'production_log/analyzer'
5
5
 
6
- Hoe.new 'production_log_analyzer', '2009022402' do |p|
6
+ Hoe.new 'production_log_analyzer', '2009022403' do |p|
7
7
  p.summary = p.paragraphs_of('README.txt', 1).join ' '
8
8
  p.description = p.paragraphs_of('README.txt', 7).join ' '
9
9
  p.author = 'Eric Hodel'
@@ -83,12 +83,17 @@ module LogParser
83
83
  @page = $1
84
84
  @ip = $2
85
85
  @time = $3
86
- when /^Completed in ([\S]+) \(\d* reqs\/sec\) \| (.+)/ then
86
+ when /^Completed in ([\S]+) \(\d* reqs\/sec\) \| (.+)/,
87
+ /^Completed in ([\S]+) \((.+)\)/ then
88
+
87
89
  next if @in_component > 0
88
- @request_time = $1.to_f
90
+ # handle millisecond times as well as fractional seconds
91
+ @times_in_milliseconds = $1[-2..-1] == 'ms'
92
+
93
+ @request_time = @times_in_milliseconds ? ($1.to_i/1000.0) : $1.to_f
89
94
  log_info = $2
90
95
 
91
- log_info = log_info.split(' | ')
96
+ log_info = log_info.split(/[,|]/)
92
97
  log_info = log_info.map do |entry|
93
98
  next nil unless entry.index(': ')
94
99
  result = entry.strip.split(': ')
@@ -97,7 +102,7 @@ module LogParser
97
102
  end
98
103
  result
99
104
  end.compact.flatten
100
-
105
+
101
106
  log_info = Hash[*log_info]
102
107
 
103
108
  @row_count = log_info['Rows'].to_i
@@ -108,9 +113,16 @@ module LogParser
108
113
  @page = log_info['Processed'] if log_info['Processed']
109
114
  @page += ".#{log_info['Response Format']}" if log_info['Response Format']
110
115
 
111
- @db_time = log_info['DB'].split(' ').first.to_f if log_info['DB']
112
- @render_time = log_info['Rendering'].split(' ').first.to_f if log_info['Rendering']
113
-
116
+ if x = (log_info['DB'])
117
+ x = x.split(' ').first
118
+ @db_time = @times_in_milliseconds ? (x.to_i/1000.0) : x.to_f
119
+ end
120
+
121
+ if x = (log_info['Rendering'] || log_info['View'])
122
+ x = x.split(' ').first
123
+ @render_time = @times_in_milliseconds ? (x.to_i/1000.0) : x.to_f
124
+ end
125
+
114
126
  when /(.+?) \(([^)]+)\) / then
115
127
  @queries << [$1, $2.to_f]
116
128
  when /^Start rendering component / then
data/test/test_parser.rb CHANGED
@@ -102,6 +102,9 @@ EOF
102
102
  Completed in 0.261485 (3 reqs/sec) | DB: 0.009325 (3%)"
103
103
 
104
104
  assert_equal 0.261485, @entry.request_time
105
+
106
+ @entry = LogParser::LogEntry.new "Completed in 13ms (View: 12, DB: 1) | 200 OK [http://www.example.com/]"
107
+ assert_equal 13/1000.0, @entry.request_time
105
108
  end
106
109
 
107
110
  def test_render_time
@@ -111,10 +114,16 @@ Completed in 0.261485 (3 reqs/sec) | DB: 0.009325 (3%)"
111
114
  Completed in 0.261485 (3 reqs/sec) | DB: 0.009325 (3%)"
112
115
 
113
116
  assert_equal 0, @entry.render_time
117
+
118
+ @entry = LogParser::LogEntry.new 'Completed in 13ms (View: 12, DB: 1) | 200 OK [http://www.example.com/]'
119
+ assert_equal 12/1000.0, @entry.render_time
114
120
  end
115
121
 
116
122
  def test_db_time
117
123
  assert_equal 0.002876, @entry.db_time
124
+
125
+ @entry = LogParser::LogEntry.new 'Completed in 13ms (View: 12, DB: 1) | 200 OK [http://www.example.com/]'
126
+ assert_equal 1/1000.0, @entry.db_time
118
127
  end
119
128
 
120
129
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erkki-production_log_analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: "2009022402"
4
+ version: "2009022403"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hodel