production_log_analyzer 1.3.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,154 +9,150 @@
9
9
 
10
10
  module LogParser
11
11
 
12
- ##
13
- # LogEntry contains a summary of log data for a single request.
14
-
15
- class LogEntry
16
-
17
- ##
18
- # Controller and action for this request
12
+ ##
13
+ # LogEntry contains a summary of log data for a single request.
19
14
 
20
- attr_reader :page
15
+ class LogEntry
21
16
 
22
- ##
23
- # Requesting IP
17
+ ##
18
+ # Controller and action for this request
24
19
 
25
- attr_reader :ip
20
+ attr_reader :page
26
21
 
27
- ##
28
- # Time the request was made
22
+ ##
23
+ # Requesting IP
29
24
 
30
- attr_reader :time
25
+ attr_reader :ip
31
26
 
32
- ##
33
- # Array of SQL queries containing query type and time taken. The
34
- # complete text of the SQL query is not saved to reduct memory usage.
27
+ ##
28
+ # Time the request was made
35
29
 
36
- attr_reader :queries
30
+ attr_reader :time
37
31
 
38
- ##
39
- # Total request time, including database, render and other.
32
+ ##
33
+ # Array of SQL queries containing query type and time taken. The
34
+ # complete text of the SQL query is not saved to reduct memory usage.
40
35
 
41
- attr_reader :request_time
36
+ attr_reader :queries
42
37
 
43
- ##
44
- # Total render time.
38
+ ##
39
+ # Total request time, including database, render and other.
45
40
 
46
- attr_reader :render_time
41
+ attr_reader :request_time
47
42
 
48
- ##
49
- # Total database time
43
+ ##
44
+ # Total render time.
50
45
 
51
- attr_reader :db_time
52
-
53
- ##
54
- # Creates a new LogEntry from the log data in +entry+.
46
+ attr_reader :render_time
55
47
 
56
- def initialize(entry)
57
- @page = nil
58
- @ip = nil
59
- @time = nil
60
- @queries = []
61
- @request_time = 0
62
- @render_time = 0
63
- @db_time = 0
64
- @in_component = 0
48
+ ##
49
+ # Total database time
65
50
 
66
- parse entry
67
- end
51
+ attr_reader :db_time
68
52
 
69
- ##
70
- # Extracts log data from +entry+, which is an Array of lines from the
71
- # same request.
72
-
73
- def parse(entry)
74
- entry.each do |line|
75
- case line
76
- when /^Parameters/, /^Cookie set/, /^Rendering/,
77
- /^Redirected/ then
78
- # nothing
79
- when /^Processing ([\S]+) \(for (.+) at (.*)\)/ then
80
- next if @in_component > 0
81
- @page = $1
82
- @ip = $2
83
- @time = $3
84
- when /^Completed in ([\S]+) .+ Rendering: ([\S]+) .+ DB: ([\S]+)/ then
85
- next if @in_component > 0
86
- @request_time = $1.to_f
87
- @render_time = $2.to_f
88
- @db_time = $3.to_f
89
- when /^Completed in ([\S]+) .+ DB: ([\S]+)/ then # Redirect
90
- next if @in_component > 0
91
- @request_time = $1.to_f
92
- @render_time = 0
93
- @db_time = $2.to_f
94
- when /(.+?) \(([^)]+)\) / then
95
- @queries << [$1, $2.to_f]
96
- when /^Start rendering component / then
97
- @in_component += 1
98
- when /^End of component rendering$/ then
99
- @in_component -= 1
100
- when /^Fragment hit: / then
101
- else
102
- raise "Can't handle #{line.inspect}" if $TESTING
103
- end
104
- end
105
- end
53
+ ##
54
+ # Creates a new LogEntry from the log data in +entry+.
55
+
56
+ def initialize(entry)
57
+ @page = nil
58
+ @ip = nil
59
+ @time = nil
60
+ @queries = []
61
+ @request_time = 0
62
+ @render_time = 0
63
+ @db_time = 0
64
+ @in_component = 0
65
+
66
+ parse entry
67
+ end
106
68
 
107
- def ==(other) # :nodoc:
108
- other.class == self.class and
109
- other.page == self.page and
110
- other.ip == self.ip and
111
- other.time == self.time and
112
- other.queries == self.queries and
113
- other.request_time == self.request_time and
114
- other.render_time == self.render_time and
115
- other.db_time == self.db_time
69
+ ##
70
+ # Extracts log data from +entry+, which is an Array of lines from the
71
+ # same request.
72
+
73
+ def parse(entry)
74
+ entry.each do |line|
75
+ case line
76
+ when /^Parameters/, /^Cookie set/, /^Rendering/,
77
+ /^Redirected/ then
78
+ # nothing
79
+ when /^Processing ([\S]+) \(for (.+) at (.*)\)/ then
80
+ next if @in_component > 0
81
+ @page = $1
82
+ @ip = $2
83
+ @time = $3
84
+ when /^Completed in ([\S]+) .+ Rendering: ([\S]+) .+ DB: ([\S]+)/ then
85
+ next if @in_component > 0
86
+ @request_time = $1.to_f
87
+ @render_time = $2.to_f
88
+ @db_time = $3.to_f
89
+ when /^Completed in ([\S]+) .+ DB: ([\S]+)/ then # Redirect
90
+ next if @in_component > 0
91
+ @request_time = $1.to_f
92
+ @render_time = 0
93
+ @db_time = $2.to_f
94
+ when /(.+?) \(([^)]+)\) / then
95
+ @queries << [$1, $2.to_f]
96
+ when /^Start rendering component / then
97
+ @in_component += 1
98
+ when /^End of component rendering$/ then
99
+ @in_component -= 1
100
+ when /^Fragment hit: / then
101
+ else # noop
102
+ # raise "Can't handle #{line.inspect}" if $TESTING
116
103
  end
104
+ end
105
+ end
117
106
 
107
+ def ==(other) # :nodoc:
108
+ other.class == self.class and
109
+ other.page == self.page and
110
+ other.ip == self.ip and
111
+ other.time == self.time and
112
+ other.queries == self.queries and
113
+ other.request_time == self.request_time and
114
+ other.render_time == self.render_time and
115
+ other.db_time == self.db_time
118
116
  end
119
117
 
120
- ##
121
- # Parses IO stream +stream+, creating a LogEntry for each recognizable log
122
- # entry.
123
- #
124
- # Log entries are recognised as starting with Processing, continuing with
125
- # the same process id through Completed.
126
-
127
- def self.parse(stream) # :yields: log_entry
128
- in_component = 0
129
- buckets = Hash.new { |h,k| h[k] = [] }
130
- comp_count = Hash.new 0
131
-
132
- stream.each_line do |line|
133
- line =~ / ([^ ]+) ([^ ]+)\[(\d+)\]: (.*)/
134
- next if $2.nil? or $2 == 'newsyslog'
135
- bucket = "#{$1}-#{$3}"
136
- data = $4
137
-
138
- buckets[bucket] << data
139
-
140
- case data
141
- when /^Start rendering component / then
142
- comp_count[bucket] += 1
143
- when /^End of component rendering$/ then
144
- comp_count[bucket] -= 1
145
- when /^Completed/ then
146
- next unless comp_count[bucket] == 0
147
- entry = buckets.delete bucket
148
- if entry.first =~ /^Processing/ then
149
- yield LogEntry.new(entry)
150
- end
151
- end
152
- end
118
+ end
119
+
120
+ ##
121
+ # Parses IO stream +stream+, creating a LogEntry for each recognizable log
122
+ # entry.
123
+ #
124
+ # Log entries are recognised as starting with Processing, continuing with
125
+ # the same process id through Completed.
126
+
127
+ def self.parse(stream) # :yields: log_entry
128
+ buckets = Hash.new { |h,k| h[k] = [] }
129
+ comp_count = Hash.new 0
130
+
131
+ stream.each_line do |line|
132
+ line =~ / ([^ ]+) ([^ ]+)\[(\d+)\]: (.*)/
133
+ next if $2.nil? or $2 == 'newsyslog'
134
+ bucket = [$1, $2, $3].join '-'
135
+ data = $4
136
+
137
+ buckets[bucket] << data
138
+
139
+ case data
140
+ when /^Start rendering component / then
141
+ comp_count[bucket] += 1
142
+ when /^End of component rendering$/ then
143
+ comp_count[bucket] -= 1
144
+ when /^Completed/ then
145
+ next unless comp_count[bucket] == 0
146
+ entry = buckets.delete bucket
147
+ next unless entry.any? { |l| l =~ /^Processing/ }
148
+ yield LogEntry.new(entry)
149
+ end
150
+ end
153
151
 
154
- buckets.each do |bucket, data|
155
- yield LogEntry.new(data)
156
- end
152
+ buckets.each do |bucket, data|
153
+ yield LogEntry.new(data)
157
154
  end
155
+ end
158
156
 
159
157
  end
160
158
 
161
- # vim: ts=4 sts=4 sw=4
162
-
@@ -1,3 +1,4 @@
1
+ //src/production_log_analyzer/dev/test/test.syslog.0.14.x.log#1 - add change 3135 (text)
1
2
  Nov 7 12:14:02 192.168.1.71 43things[24950]: Processing RssController#entries (for 10.43.199.12 at 2005-11-07 12:14:02) [GET]
2
3
  Nov 7 12:14:02 192.168.1.71 43things[24950]: Parameters: {"rss/entries/goal.html/entries/goal"=>nil, "action"=>"entries", "id"=>"goal", "controller"=>"rss", "goal_id"=>"86381"}
3
4
  Nov 7 12:14:02 192.168.1.71 43things[24950]: Rendering rss/rss2.0
@@ -0,0 +1,5 @@
1
+ //src/production_log_analyzer/dev/test/test.syslog.1.2.shortname.log#1 - add change 3135 (text)
2
+ Jan 17 16:19:22 tlucas rails[2265]: Processing Short#a (for 127.0.0.1 at 2007-01-17 16:19:22) [GET]
3
+ Jan 17 16:19:22 tlucas rails[2265]: Parameters: {"action"=>"a", "controller"=>"short"}
4
+ Jan 17 16:19:22 tlucas rails[2265]: Rendering short/a
5
+ Jan 17 16:19:22 tlucas rails[2265]: Completed in 0.02666 (37 reqs/sec) | Rendering: 0.02261 (84%) | DB: 0.00222 (8%) | 200 OK [http://127.0.0.1/short]
@@ -0,0 +1,2 @@
1
+ //src/production_log_analyzer/dev/test/test.syslog.empty.log#1 - add change 3135 (text)
2
+
data/test/test.syslog.log CHANGED
@@ -1,3 +1,4 @@
1
+ //src/production_log_analyzer/dev/test/test.syslog.log#1 - add change 3135 (text)
1
2
  Mar 7 00:00:00 online1 newsyslog[61307]: logfile turned over
2
3
  Mar 7 00:00:20 online1 rails[59600]: Goal Load (0.002112) SELECT g.*, gs.score as score FROM goals g, goal_similarities gs WHERE g.id = gs.similar_goal_id AND g.num_active_people > 0 AND gs.goal_similarity_type_id = 1 AND gs.goal_id = 59133 ORDER BY score DESC LIMIT 3
3
4
  Mar 7 00:00:20 online1 rails[59600]: Tag Load (0.001527) SELECT tags.*, count(*) as num_goals FROM tags_teams, tags, teams WHERE tags_teams.tag_id = tags.id AND tags_teams.team_id = teams.id AND teams.num_members > 0 AND teams.goal_id = 59133 GROUP BY tags.id ORDER BY num_goals DESC LIMIT 5
@@ -6,6 +7,7 @@ Mar 7 00:00:20 online1 rails[59600]: Person Load (0.001884) SELECT * FROM peo
6
7
  Mar 7 00:00:20 online1 rails[59600]: Person Load (0.001159) SELECT * FROM people WHERE id = 10519 LIMIT 1
7
8
  Mar 7 00:00:20 online1 rails[59600]: Rendering layouts/default (200 OK)
8
9
  Mar 7 00:00:20 online1 rails[59600]: Completed in 0.300741 (3 reqs/sec) | Rendering: 0.049924 (16%) | DB: 0.092428 (30%)
10
+ Mar 7 00:00:25 online2 rails[59628]: -> vsize: 83628032 rssize: 79933440 runtime: 1151489566)
9
11
  Mar 7 00:00:25 online2 rails[59628]: Processing RssController#uber (for 67.18.200.5 at Mon Mar 07 00:00:25 CST 2005)
10
12
  Mar 7 00:00:25 online2 rails[59628]: Parameters: {:id=>"author", :"rss/uber/author.html/uber/author"=>nil, :action=>"uber", :username=>"looch", :controller=>"rss"}
11
13
  Mar 7 00:00:25 online2 rails[59628]: Cookie set: auth=STUFF; path=/; expires=Thu, 05 Mar 2015 06:00:25 GMT
@@ -24,6 +26,7 @@ Mar 7 00:00:25 online1 rails[59628]: ProfileImage Load (0.001554) SELECT * FR
24
26
  Mar 7 00:00:25 online1 rails[59628]: Rendering rss/rss2.0 (200 OK)
25
27
  Mar 7 00:00:25 online1 rails[59628]: Completed in 0.034519 (28 reqs/sec) | Rendering: 0.011770 (34%) | DB: 0.007962 (23%)
26
28
  Mar 7 00:00:25 online2 rails[59628]: Completed in 0.034519 (28 reqs/sec) | Rendering: 0.011770 (34%) | DB: 0.007962 (23%)
29
+ Mar 7 00:00:25 online2 rails[59628]: <- vsize: 83628032 rssize: 79933440 runtime: 1151487080
27
30
  Mar 7 00:00:27 online1 rails[59645]: Processing ThingsController#view (for 67.18.200.5 at Mon Mar 07 00:00:27 CST 2005)
28
31
  Mar 7 00:00:27 online1 rails[59645]: Parameters: {:id=>"11891", :"things/view/11891.html/view/11891"=>nil, :action=>"view", :controller=>"things"}
29
32
  Mar 7 00:00:27 online1 rails[59645]: Cookie set: auth=STUFF; path=/; expires=Thu, 05 Mar 2015 06:00:27 GMT
@@ -24,7 +24,7 @@ class TestActionGrep < Test::Unit::TestCase
24
24
 
25
25
  lines = stdout.readlines
26
26
 
27
- assert_equal 18, lines.length
27
+ assert_equal 19, lines.length
28
28
 
29
29
  ensure
30
30
  $stdout = old_stdout
@@ -8,89 +8,89 @@ require 'production_log/analyzer'
8
8
 
9
9
  class TestEnumerable < Test::Unit::TestCase
10
10
 
11
- def test_sum
12
- assert_equal 45, (1..9).sum
13
- end
11
+ def test_sum
12
+ assert_equal 45, (1..9).sum
13
+ end
14
14
 
15
- def test_average
16
- # Ranges don't have a length
17
- assert_in_delta 5.0, (1..9).to_a.average, 0.01
18
- end
15
+ def test_average
16
+ # Ranges don't have a length
17
+ assert_in_delta 5.0, (1..9).to_a.average, 0.01
18
+ end
19
19
 
20
- def test_sample_variance
21
- assert_in_delta 6.6666, (1..9).to_a.sample_variance, 0.0001
22
- end
20
+ def test_sample_variance
21
+ assert_in_delta 6.6666, (1..9).to_a.sample_variance, 0.0001
22
+ end
23
23
 
24
- def test_standard_deviation
25
- assert_in_delta 2.5819, (1..9).to_a.standard_deviation, 0.0001
26
- end
24
+ def test_standard_deviation
25
+ assert_in_delta 2.5819, (1..9).to_a.standard_deviation, 0.0001
26
+ end
27
27
 
28
28
  end
29
29
 
30
30
  class TestSizedList < Test::Unit::TestCase
31
31
 
32
- def setup
33
- @list = SizedList.new 10 do |arr,|
34
- arr.delete_at 0
35
- true
36
- end
32
+ def setup
33
+ @list = SizedList.new 10 do |arr,|
34
+ arr.delete_at 0
35
+ true
37
36
  end
37
+ end
38
38
 
39
- def test_append
40
- assert_equal [], @list.entries
39
+ def test_append
40
+ assert_equal [], @list.entries
41
41
 
42
- (1..10).each { |i| @list << i }
43
- assert_equal 10, @list.length
44
- assert_equal((1..10).to_a, @list.entries)
42
+ (1..10).each { |i| @list << i }
43
+ assert_equal 10, @list.length
44
+ assert_equal((1..10).to_a, @list.entries)
45
45
 
46
- @list << 11
47
- assert_equal 10, @list.length
48
- assert_equal((2..11).to_a, @list.entries)
49
- end
46
+ @list << 11
47
+ assert_equal 10, @list.length
48
+ assert_equal((2..11).to_a, @list.entries)
49
+ end
50
50
 
51
51
  end
52
52
 
53
53
  class TestSlowestTimes < Test::Unit::TestCase
54
54
 
55
- def setup
56
- @list = SlowestTimes.new 10
57
- end
55
+ def setup
56
+ @list = SlowestTimes.new 10
57
+ end
58
58
 
59
- def test_that_it_works
60
- expected = []
59
+ def test_that_it_works
60
+ expected = []
61
61
 
62
- 10.downto(1) do |i|
63
- @list << [i, nil]
64
- expected << [i, nil]
65
- end
62
+ 10.downto(1) do |i|
63
+ @list << [i, nil]
64
+ expected << [i, nil]
65
+ end
66
66
 
67
- assert_equal expected, @list.entries
67
+ assert_equal expected, @list.entries
68
68
 
69
- @list << [11, nil]
70
- expected.pop
71
- expected.push [11, nil]
69
+ @list << [11, nil]
70
+ expected.pop
71
+ expected.push [11, nil]
72
72
 
73
- assert_equal 10, @list.length
74
- assert_equal expected, @list.entries
73
+ assert_equal 10, @list.length
74
+ assert_equal expected, @list.entries
75
75
 
76
- @list << [0, nil]
76
+ @list << [0, nil]
77
77
 
78
- assert_equal expected, @list.entries
79
- end
78
+ assert_equal expected, @list.entries
79
+ end
80
80
 
81
81
  end
82
82
 
83
83
  class TestAnalyzer < Test::Unit::TestCase
84
84
 
85
- def setup
86
- @analyzer = Analyzer.new 'test/test.syslog.log'
87
- @analyzer.process
88
- end
85
+ def setup
86
+ @analyzer = Analyzer.new 'test/test.syslog.log'
87
+ @analyzer.process
88
+ end
89
89
 
90
- def test_self_email
91
- email = Analyzer.email('test/test.syslog.log', 'devnull@robotcoop.com',
92
- nil, 1)
93
- expected = <<-EOF
90
+ def test_self_email
91
+ email = Analyzer.email('test/test.syslog.log', 'devnull@robotcoop.com',
92
+ nil, 1)
93
+ expected = <<-EOF
94
94
  Subject: pl_analyze
95
95
  To: devnull@robotcoop.com
96
96
  Content-Type: text/html
@@ -105,7 +105,7 @@ PeopleController#progress: 2 0.489 0.489 0.000 0.977
105
105
  PeopleController#view: 2 0.731 0.371 0.360 1.102
106
106
 
107
107
  Slowest Request Times:
108
- TeamsController#progress took 1.470s
108
+ \tTeamsController#progress took 1.470s
109
109
 
110
110
  ------------------------------------------------------------------------
111
111
 
@@ -119,7 +119,7 @@ PeopleController#progress: 2 0.415 0.415 0.000 0.830
119
119
  PeopleController#view: 2 0.338 0.149 0.189 0.486
120
120
 
121
121
  Slowest Total DB Times:
122
- TeamsController#progress took 1.144s
122
+ \tTeamsController#progress took 1.144s
123
123
 
124
124
  ------------------------------------------------------------------------
125
125
 
@@ -133,52 +133,52 @@ PeopleController#progress: 2 0.302 0.302 0.000 0.604
133
133
  PeopleController#view: 2 0.487 0.209 0.278 0.695
134
134
 
135
135
  Slowest Total Render Times:
136
- PeopleController#view took 0.695s
136
+ \tPeopleController#view took 0.695s
137
137
  </pre>
138
138
  EOF
139
139
 
140
- assert_equal expected, email
141
- end
140
+ assert_equal expected, email
141
+ end
142
142
 
143
- def test_self_envelope
144
- expected = [
145
- "Subject: pl_analyze",
146
- "To: devnull@example.com",
147
- "Content-Type: text/html"
148
- ]
143
+ def test_self_envelope
144
+ expected = [
145
+ "Subject: pl_analyze",
146
+ "To: devnull@example.com",
147
+ "Content-Type: text/html"
148
+ ]
149
149
 
150
- assert_equal expected, Analyzer.envelope('devnull@example.com')
151
- end
150
+ assert_equal expected, Analyzer.envelope('devnull@example.com')
151
+ end
152
152
 
153
- def test_self_envelope_subject
154
- expected = [
155
- "Subject: happy fancy boom",
156
- "To: devnull@example.com",
157
- "Content-Type: text/html"
158
- ]
153
+ def test_self_envelope_subject
154
+ expected = [
155
+ "Subject: happy fancy boom",
156
+ "To: devnull@example.com",
157
+ "Content-Type: text/html"
158
+ ]
159
159
 
160
- assert_equal(expected,
161
- Analyzer.envelope('devnull@example.com', 'happy fancy boom'))
162
- end
160
+ assert_equal(expected,
161
+ Analyzer.envelope('devnull@example.com', 'happy fancy boom'))
162
+ end
163
163
 
164
- def test_average_db_time
165
- assert_in_delta 0.4023761, @analyzer.average_db_time, 0.0000001
166
- end
164
+ def test_average_db_time
165
+ assert_in_delta 0.4023761, @analyzer.average_db_time, 0.0000001
166
+ end
167
167
 
168
- def test_average_render_time
169
- assert_in_delta 0.3015584, @analyzer.average_render_time, 0.0000001
170
- end
168
+ def test_average_render_time
169
+ assert_in_delta 0.3015584, @analyzer.average_render_time, 0.0000001
170
+ end
171
171
 
172
- def test_average_request_time
173
- assert_in_delta 0.6338176, @analyzer.average_request_time, 0.0000001
174
- end
172
+ def test_average_request_time
173
+ assert_in_delta 0.6338176, @analyzer.average_request_time, 0.0000001
174
+ end
175
175
 
176
- def test_db_time_std_dev
177
- assert_in_delta 0.3941380, @analyzer.db_time_std_dev, 0.0000001
178
- end
176
+ def test_db_time_std_dev
177
+ assert_in_delta 0.3941380, @analyzer.db_time_std_dev, 0.0000001
178
+ end
179
179
 
180
- def test_db_times_summary
181
- expected = <<EOF.strip
180
+ def test_db_times_summary
181
+ expected = <<EOF.strip
182
182
  DB Times Summary: Count Avg Std Dev Min Max
183
183
  ALL REQUESTS: 11 0.366 0.393 0.000 1.144
184
184
 
@@ -189,80 +189,95 @@ PeopleController#progress: 2 0.415 0.415 0.000 0.830
189
189
  PeopleController#view: 2 0.338 0.149 0.189 0.486
190
190
  EOF
191
191
 
192
- assert_equal expected, @analyzer.db_times_summary
193
- end
194
-
195
- def test_logfile_name
196
- assert_equal 'test/test.syslog.log', @analyzer.logfile_name
197
- end
198
-
199
- def test_longest_request_name
200
- assert_equal false, @analyzer.instance_variables.include?('@longest_req')
192
+ assert_equal expected, @analyzer.db_times_summary
193
+ end
201
194
 
202
- request_times = {
203
- "ThingsController#view" => [0],
204
- "TeamsController#progress" => [1],
205
- "RssController#uber" => [0],
206
- "PeopleController#progress" => [0],
207
- nil => [0],
208
- }
209
-
210
- @analyzer.instance_variable_set('@request_times', request_times)
211
-
212
- assert_equal 26, @analyzer.longest_request_name
213
- end
214
-
215
- def test_pad_request_name
216
- assert_equal 26, @analyzer.longest_request_name
217
- assert_equal("PeopleController#view: ",
218
- @analyzer.pad_request_name("PeopleController#view"))
219
- end
220
-
221
- def test_pad_request_name_nil
222
- assert_equal 26, @analyzer.longest_request_name
223
- assert_equal("Unknown: ",
224
- @analyzer.pad_request_name(nil))
195
+ def test_empty_syslog
196
+ analyzer = Analyzer.new 'test/test.syslog.empty.log'
197
+ assert_nothing_raised do
198
+ analyzer.process
199
+ analyzer.report(1)
225
200
  end
226
-
227
- def test_process
228
- expected_request_times = {
229
- "PeopleController#view" => [1.102098, 0.36021],
230
- "ThingsController#view" => [0.396183, 0.49176, 1.259728],
231
- "TeamsController#progress" => [1.469788, 0.211973],
232
- "RssController#uber" => [0.034519, 0.034519],
233
- "PeopleController#progress" => [0.977398, 0]
234
- }
235
- assert_equal expected_request_times, @analyzer.request_times
236
-
237
- expected_db_times = {
238
- "PeopleController#view" => [0.486258, 0.189119],
239
- "ThingsController#view" => [0.122158, 0.172767, 0.914192],
240
- "TeamsController#progress" => [1.143577, 0.149357],
241
- "RssController#uber" => [0.007962, 0.007962],
242
- "PeopleController#progress" => [0.830409, 0]
243
- }
244
- assert_equal expected_db_times, @analyzer.db_times
245
-
246
- expected_render_times = {
247
- "PeopleController#view" => [0.695476, 0.277921],
248
- "ThingsController#view" => [0.107987, 0.197126, 0.505973],
249
- "TeamsController#progress" => [0, 0],
250
- "RssController#uber" => [0.01177, 0.01177],
251
- "PeopleController#progress" => [0.604444, 0]
252
- }
253
- assert_equal expected_render_times, @analyzer.render_times
254
-
255
- # expected_query_times = {
256
- # }
257
- # assert_equal expected_query_times, @analyzer.query_times
201
+ assert_equal "No requests to analyze", analyzer.report(1)
202
+ end
203
+
204
+ def test_logfile_name
205
+ assert_equal 'test/test.syslog.log', @analyzer.logfile_name
206
+ end
207
+
208
+ def test_longest_request_name
209
+ assert_equal false, @analyzer.instance_variables.include?('@longest_req')
210
+
211
+ request_times = {
212
+ "ThingsController#view" => [0],
213
+ "TeamsController#progress" => [1],
214
+ "RssController#uber" => [0],
215
+ "PeopleController#progress" => [0],
216
+ nil => [0],
217
+ }
218
+
219
+ @analyzer.instance_variable_set('@request_times', request_times)
220
+
221
+ assert_equal 26, @analyzer.longest_request_name
222
+ end
223
+
224
+ def test_pad_request_name
225
+ assert_equal 26, @analyzer.longest_request_name
226
+ assert_equal("PeopleController#view: ",
227
+ @analyzer.pad_request_name("PeopleController#view"))
228
+ end
229
+
230
+ def test_pad_request_name_nil
231
+ assert_equal 26, @analyzer.longest_request_name
232
+ assert_equal("Unknown: ",
233
+ @analyzer.pad_request_name(nil))
234
+ end
235
+
236
+ def test_pad_request_name_short
237
+ analyzer = Analyzer.new 'test/test.syslog.1.2.shortname.log'
238
+ analyzer.process
239
+ longer_request_name_value = " " * (analyzer.longest_request_name + 1)
240
+ assert_nothing_raised do
241
+ analyzer.pad_request_name(longer_request_name_value)
258
242
  end
259
-
260
- def test_render_time_std_dev
261
- assert_in_delta 0.2513925, @analyzer.render_time_std_dev, 0.0000001
262
- end
263
-
264
- def test_render_times_summary
265
- expected = <<EOF.strip
243
+ assert_equal longer_request_name_value + ":", analyzer.pad_request_name(longer_request_name_value)
244
+ end
245
+
246
+ def test_process
247
+ expected_request_times = {
248
+ "PeopleController#view" => [1.102098, 0.36021],
249
+ "ThingsController#view" => [0.396183, 0.49176, 1.259728],
250
+ "TeamsController#progress" => [1.469788, 0.211973],
251
+ "RssController#uber" => [0.034519, 0.034519],
252
+ "PeopleController#progress" => [0.977398, 0]
253
+ }
254
+ assert_equal expected_request_times, @analyzer.request_times
255
+
256
+ expected_db_times = {
257
+ "PeopleController#view" => [0.486258, 0.189119],
258
+ "ThingsController#view" => [0.122158, 0.172767, 0.914192],
259
+ "TeamsController#progress" => [1.143577, 0.149357],
260
+ "RssController#uber" => [0.007962, 0.007962],
261
+ "PeopleController#progress" => [0.830409, 0]
262
+ }
263
+ assert_equal expected_db_times, @analyzer.db_times
264
+
265
+ expected_render_times = {
266
+ "PeopleController#view" => [0.695476, 0.277921],
267
+ "ThingsController#view" => [0.107987, 0.197126, 0.505973],
268
+ "TeamsController#progress" => [0, 0],
269
+ "RssController#uber" => [0.01177, 0.01177],
270
+ "PeopleController#progress" => [0.604444, 0]
271
+ }
272
+ assert_equal expected_render_times, @analyzer.render_times
273
+ end
274
+
275
+ def test_render_time_std_dev
276
+ assert_in_delta 0.2513925, @analyzer.render_time_std_dev, 0.0000001
277
+ end
278
+
279
+ def test_render_times_summary
280
+ expected = <<EOF.strip
266
281
  Render Times Summary: Count Avg Std Dev Min Max
267
282
  ALL REQUESTS: 11 0.219 0.253 0.000 0.695
268
283
 
@@ -273,11 +288,11 @@ PeopleController#progress: 2 0.302 0.302 0.000 0.604
273
288
  PeopleController#view: 2 0.487 0.209 0.278 0.695
274
289
  EOF
275
290
 
276
- assert_equal expected, @analyzer.render_times_summary
277
- end
291
+ assert_equal expected, @analyzer.render_times_summary
292
+ end
278
293
 
279
- def test_report
280
- expected = <<-EOF
294
+ def test_report
295
+ expected = <<-EOF
281
296
  Request Times Summary: Count Avg Std Dev Min Max
282
297
  ALL REQUESTS: 11 0.576 0.508 0.000 1.470
283
298
 
@@ -288,16 +303,16 @@ PeopleController#progress: 2 0.489 0.489 0.000 0.977
288
303
  PeopleController#view: 2 0.731 0.371 0.360 1.102
289
304
 
290
305
  Slowest Request Times:
291
- TeamsController#progress took 1.470s
292
- ThingsController#view took 1.260s
293
- PeopleController#view took 1.102s
294
- PeopleController#progress took 0.977s
295
- ThingsController#view took 0.492s
296
- ThingsController#view took 0.396s
297
- PeopleController#view took 0.360s
298
- TeamsController#progress took 0.212s
299
- RssController#uber took 0.035s
300
- RssController#uber took 0.035s
306
+ \tTeamsController#progress took 1.470s
307
+ \tThingsController#view took 1.260s
308
+ \tPeopleController#view took 1.102s
309
+ \tPeopleController#progress took 0.977s
310
+ \tThingsController#view took 0.492s
311
+ \tThingsController#view took 0.396s
312
+ \tPeopleController#view took 0.360s
313
+ \tTeamsController#progress took 0.212s
314
+ \tRssController#uber took 0.035s
315
+ \tRssController#uber took 0.035s
301
316
 
302
317
  ------------------------------------------------------------------------
303
318
 
@@ -311,16 +326,16 @@ PeopleController#progress: 2 0.415 0.415 0.000 0.830
311
326
  PeopleController#view: 2 0.338 0.149 0.189 0.486
312
327
 
313
328
  Slowest Total DB Times:
314
- TeamsController#progress took 1.144s
315
- ThingsController#view took 0.914s
316
- PeopleController#progress took 0.830s
317
- PeopleController#view took 0.486s
318
- PeopleController#view took 0.189s
319
- ThingsController#view took 0.173s
320
- TeamsController#progress took 0.149s
321
- ThingsController#view took 0.122s
322
- RssController#uber took 0.008s
323
- RssController#uber took 0.008s
329
+ \tTeamsController#progress took 1.144s
330
+ \tThingsController#view took 0.914s
331
+ \tPeopleController#progress took 0.830s
332
+ \tPeopleController#view took 0.486s
333
+ \tPeopleController#view took 0.189s
334
+ \tThingsController#view took 0.173s
335
+ \tTeamsController#progress took 0.149s
336
+ \tThingsController#view took 0.122s
337
+ \tRssController#uber took 0.008s
338
+ \tRssController#uber took 0.008s
324
339
 
325
340
  ------------------------------------------------------------------------
326
341
 
@@ -334,27 +349,27 @@ PeopleController#progress: 2 0.302 0.302 0.000 0.604
334
349
  PeopleController#view: 2 0.487 0.209 0.278 0.695
335
350
 
336
351
  Slowest Total Render Times:
337
- PeopleController#view took 0.695s
338
- PeopleController#progress took 0.604s
339
- ThingsController#view took 0.506s
340
- PeopleController#view took 0.278s
341
- ThingsController#view took 0.197s
342
- ThingsController#view took 0.108s
343
- RssController#uber took 0.012s
344
- RssController#uber took 0.012s
345
- TeamsController#progress took 0.000s
346
- TeamsController#progress took 0.000s
352
+ \tPeopleController#view took 0.695s
353
+ \tPeopleController#progress took 0.604s
354
+ \tThingsController#view took 0.506s
355
+ \tPeopleController#view took 0.278s
356
+ \tThingsController#view took 0.197s
357
+ \tThingsController#view took 0.108s
358
+ \tRssController#uber took 0.012s
359
+ \tRssController#uber took 0.012s
360
+ \tTeamsController#progress took 0.000s
361
+ \tTeamsController#progress took 0.000s
347
362
  EOF
348
363
 
349
- assert_equal expected, @analyzer.report(10)
350
- end
364
+ assert_equal expected, @analyzer.report(10)
365
+ end
351
366
 
352
- def test_request_time_std_dev
353
- assert_in_delta 0.4975667, @analyzer.request_time_std_dev, 0.0000001
354
- end
367
+ def test_request_time_std_dev
368
+ assert_in_delta 0.4975667, @analyzer.request_time_std_dev, 0.0000001
369
+ end
355
370
 
356
- def test_request_times_summary
357
- expected = <<EOF.strip
371
+ def test_request_times_summary
372
+ expected = <<EOF.strip
358
373
  Request Times Summary: Count Avg Std Dev Min Max
359
374
  ALL REQUESTS: 11 0.576 0.508 0.000 1.470
360
375
 
@@ -365,41 +380,41 @@ PeopleController#progress: 2 0.489 0.489 0.000 0.977
365
380
  PeopleController#view: 2 0.731 0.371 0.360 1.102
366
381
  EOF
367
382
 
368
- assert_equal expected, @analyzer.request_times_summary
369
- end
370
-
371
- def test_slowest_db_times
372
- times = @analyzer.slowest_db_times 3
373
- assert_equal 3, times.length
374
- expected = [
375
- [1.143577, "TeamsController#progress"],
376
- [0.914192, "ThingsController#view"],
377
- [0.830409, "PeopleController#progress"]
378
- ]
379
- assert_equal expected, times
380
- end
381
-
382
- def test_slowest_request_times
383
- times = @analyzer.slowest_request_times 3
384
- assert_equal 3, times.length
385
- expected = [
386
- [1.469788, "TeamsController#progress"],
387
- [1.259728, "ThingsController#view"],
388
- [1.102098, "PeopleController#view"]
389
- ]
390
- assert_equal expected, times
391
- end
392
-
393
- def test_slowest_render_times
394
- times = @analyzer.slowest_render_times 3
395
- assert_equal 3, times.length
396
- expected = [
397
- [0.695476, "PeopleController#view"],
398
- [0.604444, "PeopleController#progress"],
399
- [0.505973, "ThingsController#view"]
400
- ]
401
- assert_equal expected, times
402
- end
383
+ assert_equal expected, @analyzer.request_times_summary
384
+ end
385
+
386
+ def test_slowest_db_times
387
+ times = @analyzer.slowest_db_times 3
388
+ assert_equal 3, times.length
389
+ expected = [
390
+ [1.143577, "TeamsController#progress"],
391
+ [0.914192, "ThingsController#view"],
392
+ [0.830409, "PeopleController#progress"]
393
+ ]
394
+ assert_equal expected, times
395
+ end
396
+
397
+ def test_slowest_request_times
398
+ times = @analyzer.slowest_request_times 3
399
+ assert_equal 3, times.length
400
+ expected = [
401
+ [1.469788, "TeamsController#progress"],
402
+ [1.259728, "ThingsController#view"],
403
+ [1.102098, "PeopleController#view"]
404
+ ]
405
+ assert_equal expected, times
406
+ end
407
+
408
+ def test_slowest_render_times
409
+ times = @analyzer.slowest_render_times 3
410
+ assert_equal 3, times.length
411
+ expected = [
412
+ [0.695476, "PeopleController#view"],
413
+ [0.604444, "PeopleController#progress"],
414
+ [0.505973, "ThingsController#view"]
415
+ ]
416
+ assert_equal expected, times
417
+ end
403
418
 
404
419
  end
405
420