oink 0.9.3 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,267 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
-
3
- module Oink::Reports
4
- describe MemoryUsageReport do
5
-
6
- TEN_MEGS = 10 * 1024
7
-
8
- describe "short summary with frequent offenders" do
9
-
10
- it "should report actions which exceed the threshold once" do
11
- str = <<-STR
12
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
13
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
14
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
15
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
16
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
17
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
18
- STR
19
-
20
- io = StringIO.new(str)
21
- output = PsuedoOutput.new
22
- MemoryUsageReport.new(io, TEN_MEGS).print(output)
23
- output.should include("1, Media#show")
24
- end
25
-
26
- it "should not report actions which do not exceed the threshold" do
27
- threshold = 10
28
-
29
- str = <<-STR
30
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
31
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
32
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
33
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
34
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS} | PID: 4413
35
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
36
- STR
37
-
38
- io = StringIO.new(str)
39
- output = PsuedoOutput.new
40
- MemoryUsageReport.new(io, TEN_MEGS).print(output)
41
- output.should_not include("1, Media#show")
42
- end
43
-
44
- it "should report actions which exceed the threshold multiple times" do
45
- str = <<-STR
46
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
47
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
48
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
49
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
50
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
51
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
52
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
53
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{(TEN_MEGS * 2) + 2} | PID: 4413
54
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
55
- STR
56
-
57
- io = StringIO.new(str)
58
- output = PsuedoOutput.new
59
- MemoryUsageReport.new(io, TEN_MEGS).print(output)
60
- output.should include("2, Media#show")
61
- end
62
-
63
- it "should order actions by most exceeded" do
64
- str = <<-STR
65
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
66
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
67
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
68
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
69
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
70
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
71
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
72
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{(TEN_MEGS * 2) + 2} | PID: 4413
73
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
74
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
75
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{(TEN_MEGS * 3) + 3} | PID: 4413
76
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
77
- STR
78
-
79
- io = StringIO.new(str)
80
- output = PsuedoOutput.new
81
- MemoryUsageReport.new(io, TEN_MEGS).print(output)
82
- output[-2].should == "2, Media#show"
83
- output[-1].should == "1, Users#show"
84
- end
85
-
86
- it "should not report actions which do not complete properly" do
87
- threshold = 10
88
-
89
- str = <<-STR
90
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
91
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
92
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
93
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
94
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
95
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
96
- STR
97
-
98
- io = StringIO.new(str)
99
- output = PsuedoOutput.new
100
- MemoryUsageReport.new(io, TEN_MEGS).print(output)
101
- output.should_not include("1, Media#show")
102
- end
103
-
104
- it "should not report actions from different pids" do
105
- str = <<-STR
106
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
107
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
108
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
109
- Feb 01 01:58:29 ey04-s00297 rails[5513]: Oink Action: Media#show
110
- Feb 01 01:58:30 ey04-s00297 rails[5513]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
111
- Feb 01 01:58:30 ey04-s00297 rails[5513]: Oink Log Entry Complete
112
- STR
113
-
114
- io = StringIO.new(str)
115
- output = PsuedoOutput.new
116
- MemoryUsageReport.new(io, TEN_MEGS).print(output)
117
- output.should_not include("1, Media#show")
118
- end
119
-
120
- describe "summary with top 10 offenses" do
121
-
122
- it "should only report requests over threshold" do
123
- str = <<-STR
124
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
125
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
126
- Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
127
- Feb 01 01:58:32 ey04-s00297 rails[4413]: Oink Action: Media#show
128
- Feb 01 01:58:33 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
129
- Feb 01 01:58:34 ey04-s00297 rails[4413]: Oink Log Entry Complete
130
- STR
131
-
132
- io = StringIO.new(str)
133
- output = PsuedoOutput.new
134
- MemoryUsageReport.new(io, TEN_MEGS).print(output)
135
- output.should include("1. Feb 01 01:58:34, #{TEN_MEGS + 1} KB, Media#show")
136
- end
137
-
138
- it "should not include requests which are not over the threshold" do
139
- str = <<-STR
140
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
141
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
142
- Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
143
- Feb 01 01:58:32 ey04-s00297 rails[4413]: Oink Action: Media#show
144
- Feb 01 01:58:33 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS} | PID: 4413
145
- Feb 01 01:58:34 ey04-s00297 rails[4413]: Oink Log Entry Complete
146
- STR
147
-
148
- io = StringIO.new(str)
149
- output = PsuedoOutput.new
150
- MemoryUsageReport.new(io, TEN_MEGS).print(output)
151
- output.should_not include("1. Feb 01 01:58:34, #{TEN_MEGS + 1} KB, Media#show")
152
- end
153
-
154
- it "should order offenses from biggest to smallest" do
155
- str = <<-STR
156
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
157
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
158
- Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
159
- Feb 01 01:58:32 ey04-s00297 rails[4413]: Oink Action: Media#show
160
- Feb 01 01:58:33 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
161
- Feb 01 01:58:34 ey04-s00297 rails[4413]: Oink Log Entry Complete
162
- Feb 01 01:58:35 ey04-s00297 rails[4413]: Oink Action: Details#show
163
- Feb 01 01:58:36 ey04-s00297 rails[4413]: Memory usage: #{(TEN_MEGS * 2) + 2} | PID: 4413
164
- Feb 01 01:58:37 ey04-s00297 rails[4413]: Oink Log Entry Complete
165
- STR
166
-
167
- io = StringIO.new(str)
168
- output = PsuedoOutput.new
169
- MemoryUsageReport.new(io, TEN_MEGS).print(output)
170
- output[4].should == "1. Feb 01 01:58:34, #{TEN_MEGS + 1} KB, Media#show"
171
- output[5].should == "2. Feb 01 01:58:37, #{TEN_MEGS + 1} KB, Details#show"
172
- end
173
-
174
- end
175
-
176
- # it "should report the time span" do
177
- # str = <<-STR
178
- # Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
179
- # Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
180
- # Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
181
- # Mar 13 01:58:29 ey04-s00297 rails[5513]: Oink Action: Media#show
182
- # Mar 13 01:58:30 ey04-s00297 rails[5513]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
183
- # Mar 13 03:58:30 ey04-s00297 rails[5513]: Oink Log Entry Complete
184
- # STR
185
- #
186
- # io = StringIO.new(str)
187
- # output = PsuedoOutput.new
188
- # MemoryUsageReport.new(io, TEN_MEGS).each_line do |line|
189
- # output << line
190
- # end
191
- # output.first.should == "Feb 01 01:58:29 - Mar 13 03:58:30"
192
- # end
193
-
194
- end
195
-
196
- describe "verbose format" do
197
- it "should print the full lines of actions exceeding the threshold" do
198
- str = <<-STR
199
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
200
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Parameters: {"id"=>"2332", "controller"=>"users"}
201
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
202
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
203
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
204
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Parameters: {"id"=>"22900", "controller"=>"media"}
205
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
206
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
207
- STR
208
- io = StringIO.new(str)
209
- output = PsuedoOutput.new
210
- MemoryUsageReport.new(io, TEN_MEGS, :format => :verbose).print(output)
211
- output[3..6].should == str.split("\n")[4..7].map { |o| o.strip }
212
- end
213
-
214
- it "should handle actions which do not complete properly" do
215
- threshold = 10
216
-
217
- str = <<-STR
218
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
219
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
220
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
221
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
222
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
223
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
224
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing ActorController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
225
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{(TEN_MEGS * 2) + 2} | PID: 4413
226
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
227
- STR
228
-
229
- io = StringIO.new(str)
230
- output = PsuedoOutput.new
231
- MemoryUsageReport.new(io, TEN_MEGS, :format => :verbose).print(output)
232
- output[3..5].should == str.split("\n")[6..8].map { |o| o.strip }
233
- end
234
- end
235
-
236
- describe "multiple io streams" do
237
- it "should accept multiple files" do
238
-
239
- str1 = <<-STR
240
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
241
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
242
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
243
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
244
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
245
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
246
- STR
247
-
248
- str2 = <<-STR
249
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
250
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
251
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
252
- Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
253
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
254
- Feb 01 01:58:30 ey04-s00297 rails[4413]: Oink Log Entry Complete
255
- STR
256
-
257
- io1 = StringIO.new(str1)
258
- io2 = StringIO.new(str2)
259
- output = PsuedoOutput.new
260
- MemoryUsageReport.new([io1, io2], TEN_MEGS).print(output)
261
- output.should include("2, Media#show")
262
- end
263
-
264
- end
265
-
266
- end
267
- end
@@ -1,22 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
-
3
- module Oink::Reports
4
- describe Request do
5
- it "should be comparable" do
6
- lr1 = Request.new("Controller#Action", "February 1 10:20", [], 10)
7
- lr2 = Request.new("Controller#Action", "February 1 10:20", [], 5)
8
-
9
- (lr1 > lr2).should == true
10
- (lr1 == lr2).should == false
11
- end
12
-
13
- it "should sort by memory used" do
14
- lr1 = Request.new("Controller#Action", "February 1 10:20", [], 10)
15
- lr2 = Request.new("Controller#Action", "February 1 10:20", [], 5)
16
- lr3 = Request.new("Controller#Action", "February 1 10:20", [], 30)
17
-
18
- [lr1, lr2, lr3].sort.should == [lr2, lr1, lr3]
19
- end
20
-
21
- end
22
- end
@@ -1,74 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
-
3
- module Oink::Reports
4
- describe PriorityQueue do
5
- describe "size" do
6
-
7
- it "should report the right size" do
8
- pq = PriorityQueue.new(5)
9
- pq.push(1)
10
- pq.size.should == 1
11
- pq.push(2)
12
- pq.size.should == 2
13
- end
14
-
15
- it "should be limited to the size initialized with" do
16
- pq = PriorityQueue.new(5)
17
- pq.push(1)
18
- pq.push(2)
19
- pq.push(3)
20
- pq.push(4)
21
- pq.push(5)
22
- pq.push(6)
23
- pq.size.should == 5
24
- end
25
-
26
- end
27
-
28
- describe "order" do
29
-
30
- it "should be in order from highest to lowest" do
31
- pq = PriorityQueue.new(5)
32
- pq.push(1)
33
- pq.push(2)
34
- pq.push(3)
35
- pq.to_a.should == [3,2,1]
36
- end
37
-
38
- it "should throw out the lower value when adding a new value" do
39
- pq = PriorityQueue.new(3)
40
- pq.push(1)
41
- pq.push(2)
42
- pq.push(3)
43
- pq.push(4)
44
- pq.to_a.should == [4,3,2]
45
- end
46
-
47
- it "should not make it into the queue if it's smaller than the items in the queue" do
48
- pq = PriorityQueue.new(3)
49
- pq.push(2)
50
- pq.push(3)
51
- pq.push(4)
52
- pq.push(1)
53
- pq.to_a.should == [4,3,2]
54
- end
55
-
56
- end
57
-
58
- describe "each" do
59
- it "should return each item in turn" do
60
- arr = []
61
- pq = PriorityQueue.new(5)
62
- pq.push(2)
63
- pq.push(3)
64
- pq.push(4)
65
- pq.push(1)
66
- pq.push(5)
67
- pq.each do |i|
68
- arr << i
69
- end
70
- arr.should == [5,4,3,2,1]
71
- end
72
- end
73
- end
74
- end
@@ -1,21 +0,0 @@
1
- require "rspec"
2
- require "ostruct"
3
- require "logger"
4
-
5
- require 'helpers/database'
6
- require 'fakes/fake_application_controller'
7
- require 'fakes/psuedo_output'
8
-
9
- require 'oink/cli'
10
- require 'oink/rails'
11
-
12
- RSpec.configure do |config|
13
-
14
- config.before :suite do
15
- setup_memory_database
16
- Pig = Class.new(ActiveRecord::Base)
17
- Pen = Class.new(ActiveRecord::Base)
18
- Pig.belongs_to :pen
19
- end
20
-
21
- end