rawk_log 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,6 +32,7 @@ module RawkLog
32
32
  def initialize(args)
33
33
  @start_time = Time.now
34
34
  build_arg_hash(args)
35
+ @new_log_format = nil
35
36
  end
36
37
 
37
38
  def run
@@ -112,57 +113,60 @@ module RawkLog
112
113
 
113
114
  # Old: Completed in 0.45141 (2 reqs/sec) | Rendering: 0.25965 (57%) | DB: 0.06300 (13%) | 200 OK [http://localhost/jury/proposal/312]
114
115
  # New: Completed in 100ms (View: 40, DB: 4)
115
- unless defined? @new_log_format
116
- @new_log_format = $_ =~ /Completed in \d+ms/
116
+ if @new_log_format.nil?
117
+ @new_log_format = ! ($_ =~ /Completed in \d+ms/)
117
118
  end
118
119
 
119
120
  if @new_log_format
120
121
  if @db_time
121
- time_string = $_[/DB: \d+/]
122
+ time_string = $_[/DB: \d+\.\d+/]
122
123
  elsif @render_time
123
- time_string = $_[/View: \d+/]
124
+ time_string = $_[/(View|Rendering): \d+\.\d+/]
124
125
  else
125
- time_string = $_[/Completed in \d+ms/]
126
+ time_string = $_[/Completed in \d+\.\d+/]
126
127
  end
127
- time_string = time_string[/\d+/] if time_string
128
- time = time_string.to_i if time_string
128
+ time_string = time_string[/\d+\.\d+/] if time_string
129
+ time = time_string.to_f if time_string
129
130
  else
130
131
  if @db_time
131
- time_string = $_[/DB: \d+\.\d+/]
132
+ time_string = $_[/DB: \d+/]
132
133
  elsif @render_time
133
- time_string = $_[/Rendering: \d+\.\d+/]
134
+ time_string = $_[/View: \d+/]
134
135
  else
135
- time_string = $_[/Completed in \d+\.\d+/]
136
+ time_string = $_[/Completed in \d+ms/]
136
137
  end
137
- time_string = time_string[/\d+\.\d+/] if time_string
138
- time = time_string.to_f if time_string
138
+ time_string = time_string[/\d+/] if time_string
139
+ time = time_string.to_i if time_string
139
140
  end
141
+
140
142
 
141
143
 
142
144
  #if pids are not specified then we use the url for hashing
143
145
  #the below regexp turns "[http://spongecell.com/calendar/view/bob]" to "/calendar/view"
144
146
  unless key
147
+ uri = $_[/\[[^\]]+\]/]
148
+ if uri and uri != ''
149
+ key = if @force_url_use
150
+ (uri.gsub(/\S+\/\/(\w|\.)*/,''))[/[^\?\]]*/]
151
+ else
152
+ data = uri.gsub(/\S+\/\/(\w|\.)*/,'')
153
+ s = data.gsub(/(\?.*)|\]$/,'').split("/")
145
154
 
146
- key = if @force_url_use
147
- ($_[/\[[^\]]+\]/].gsub(/\S+\/\/(\w|\.)*/,''))[/[^\?\]]*/]
148
- else
149
- data = $_[/\[[^\]]+\]/].gsub(/\S+\/\/(\w|\.)*/,'')
150
- s = data.gsub(/(\?.*)|\]$/,'').split("/")
151
-
152
- keywords = s.inject([]) do |keywords, word|
153
- if is_id?(word.to_s)
154
- keywords << '{ID}'
155
- elsif !word.to_s.empty?
156
- keywords << word.to_s
155
+ keywords = s.inject([]) do |keywords, word|
156
+ if is_id?(word.to_s)
157
+ keywords << '{ID}'
158
+ elsif !word.to_s.empty?
159
+ keywords << word.to_s
160
+ end
161
+ keywords
157
162
  end
158
- keywords
163
+ keywords[-1] = '{filename}' if ! keywords.empty? and is_filename?(keywords[-1])
164
+ k = "/#{keywords.join("/")}"
159
165
  end
160
- keywords[-1] = '{filename}' if ! keywords.empty? and is_filename?(keywords[-1])
161
- k = "/#{keywords.join("/")}"
162
166
  end
163
167
  end
164
168
 
165
- if (@from.nil? or @from <= date) and (@to.nil? or @to >= date) # date criteria here
169
+ if key and (@from.nil? or @from <= date) and (@to.nil? or @to >= date) # date criteria here
166
170
  @stat_hash.add(key,time)
167
171
  @total_stat.add(time)
168
172
  if @worst_requests.length<@worst_request_length || @worst_requests[@worst_request_length-1][0]<time
@@ -177,7 +181,7 @@ module RawkLog
177
181
  title = "Log Analysis of #{@db_time ? 'DB' : @render_time ? 'render' : 'total'} request times#{@from ? %Q( from #{@from.to_s}) : ""}#{@to ? %Q( through #{@to.to_s}) : ""}"
178
182
  puts title
179
183
  puts "=" * title.size
180
- puts ""
184
+ puts "(Times are in milliseconds except where indicated)\n"
181
185
  label_size = @stat_hash.print()
182
186
  if @stat_hash.empty?
183
187
  puts @total_stat.header(label_size)
data/lib/rawk_log/stat.rb CHANGED
@@ -4,8 +4,7 @@ module RawkLog
4
4
 
5
5
  DEFAULT_LABEL_SIZE = 30
6
6
 
7
- HEADER = "Count Sum Max Median Avg Min Std"
8
- HEADER_NEW_LOG_FORMAT = "Count Sum(s) Max Median Avg Min Std"
7
+ HEADER = "Count Sum(secs) Max Median Avg Min Std"
9
8
 
10
9
  def initialize(key)
11
10
  @key=key
@@ -31,8 +30,7 @@ module RawkLog
31
30
  end
32
31
 
33
32
  def header(label_size = DEFAULT_LABEL_SIZE)
34
- header = @new_log_format ? HEADER_NEW_LOG_FORMAT : HEADER
35
- sprintf "%*s %s" % [-label_size, "Request", header]
33
+ sprintf "%*s %s" % [-label_size, "Request", HEADER]
36
34
  end
37
35
 
38
36
  def key
@@ -78,7 +76,8 @@ module RawkLog
78
76
  if @new_log_format
79
77
  sprintf("%*s %6d %9.2f %7d %7d %7d %7d %7d",-label_size, key,count,(sum.to_f/1000),max,median,average,min,standard_deviation)
80
78
  else
81
- sprintf("%*s %6d %9.2f %7.2f %7.2f %7.2f %7.2f %7.2f",-label_size,key,count,sum,max,median,average,min,standard_deviation)
79
+ sprintf("%*s %6d %9.2f %7d %7d %7d %7d %7d",-label_size, key,count,sum,max*1000.0,median*1000.0,average*1000.0,min*1000.0,standard_deviation*1000.0)
80
+ #sprintf("%*s %6d %9.2f %7.2f %7.2f %7.2f %7.2f %7.2f",-label_size,key,count,sum,max,median,average,min,standard_deviation)
82
81
  end
83
82
  else
84
83
  sprintf("%*s %6d",-label_size,key,0)
@@ -1,3 +1,3 @@
1
1
  module RawkLog
2
- VERSION = "2.2.2"
2
+ VERSION = "2.3.0"
3
3
  end
data/test/empty_test.rb CHANGED
@@ -10,7 +10,7 @@ class EmptyTest < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  def test_outputs_header
13
- assert_match(/^Request +Count +Sum +Max +Median +Avg +Min +Std$/, @output)
13
+ assert_match(/^Request +Count +Sum\(secs\) +Max +Median +Avg +Min +Std$/, @output)
14
14
  end
15
15
 
16
16
  def test_lists_zero_entries
@@ -28,3 +28,4 @@ Completed in 5ms (View: 2, DB: 0) | 200 OK [http://0.0.0.0/items]
28
28
  Processing DocumentController#download (for 12.13.14.15 at 2012-12-13 11:49:03) [GET]
29
29
  Completed in 936ms (View: 1, DB: 31) | 200 OK [http://www.example.com/document/download/96164/Form 6 - Occupancy permit-2034-20156 - Unit 1.docx]
30
30
 
31
+ Completed in 0.03599 (27 reqs/sec) | Rendering: 0.02954 (82%) | DB: 0.00196 (5%) | 200 OK [http://www.exampl
@@ -14,7 +14,7 @@ class MixedRails40Test < Test::Unit::TestCase
14
14
  end
15
15
 
16
16
  def test_outputs_header
17
- assert_match(/^Request +Count +Sum +Max +Median +Avg +Min +Std$/, @output)
17
+ assert_match(/^Request +Count +Sum\(secs\) +Max +Median +Avg +Min +Std$/, @output)
18
18
  end
19
19
 
20
20
  def test_has_top_lists
data/test/rails23_test.rb CHANGED
@@ -18,7 +18,7 @@ class Rails23Test < Test::Unit::TestCase
18
18
  end
19
19
 
20
20
  def test_outputs_header
21
- assert_match(/^Request +Count +Sum\(s\) +Max +Median +Avg +Min +Std$/, @output)
21
+ assert_match(/^Request +Count +Sum\(secs\) +Max +Median +Avg +Min +Std$/, @output)
22
22
  end
23
23
 
24
24
  def test_finds_entries
data/test/rails40_test.rb CHANGED
@@ -18,7 +18,7 @@ class Rails40Test < Test::Unit::TestCase
18
18
  end
19
19
 
20
20
  def test_outputs_header
21
- assert_match(/^Request +Count +Sum +Max +Median +Avg +Min +Std$/, @output)
21
+ assert_match(/^Request +Count +Sum\(secs\) +Max +Median +Avg +Min +Std$/, @output)
22
22
  end
23
23
 
24
24
  def test_finds_entries
data/test/unknown_test.rb CHANGED
@@ -10,7 +10,7 @@ class UnknownTest < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  def test_outputs_header
13
- assert_match(/^Request +Count +Sum +Max +Median +Avg +Min +Std$/, @output)
13
+ assert_match(/^Request +Count +Sum\(secs\) +Max +Median +Avg +Min +Std$/, @output)
14
14
  end
15
15
 
16
16
  def test_no_top_lists
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rawk_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: