oink 0.1.2 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +15 -29
- data/Rakefile +4 -6
- data/bin/oink +2 -2
- data/lib/oink.rb +1 -9
- data/lib/oink/cli.rb +71 -67
- data/lib/oink/instrumentation.rb +2 -0
- data/lib/oink/instrumentation/active_record.rb +63 -0
- data/lib/oink/instrumentation/memory_snapshot.rb +119 -0
- data/lib/oink/middleware.rb +48 -0
- data/lib/oink/rails/instance_type_counter.rb +8 -62
- data/lib/oink/rails/memory_usage_logger.rb +11 -33
- data/lib/oink/reports/active_record_instantiation_oinked_request.rb +13 -0
- data/lib/oink/reports/active_record_instantiation_report.rb +67 -0
- data/lib/oink/reports/base.rb +38 -0
- data/lib/oink/reports/memory_oinked_request.rb +13 -0
- data/lib/oink/reports/memory_usage_report.rb +71 -0
- data/lib/oink/reports/priority_queue.rb +41 -0
- data/lib/oink/reports/request.rb +20 -0
- data/lib/oink/utils/hash_utils.rb +9 -0
- data/spec/fakes/fake_application_controller.rb +30 -0
- data/spec/fakes/psuedo_output.rb +7 -0
- data/spec/helpers/database.rb +20 -0
- data/spec/{rails → oink/instrumentation}/instance_type_counter_spec.rb +11 -9
- data/spec/oink/instrumentation/memory_snapshot_spec.rb +84 -0
- data/spec/oink/middleware_spec.rb +73 -0
- data/spec/oink/rails/instance_type_counter_spec.rb +52 -0
- data/spec/oink/rails/memory_usage_logger_spec.rb +23 -0
- data/spec/oink/reports/active_record_instantiation_report_spec.rb +193 -0
- data/spec/oink/reports/memory_usage_report_spec.rb +267 -0
- data/spec/oink/reports/oinked_request_spec.rb +22 -0
- data/spec/oink/reports/priority_queue_spec.rb +74 -0
- data/spec/spec_helper.rb +10 -26
- metadata +158 -29
- data/lib/oink/active_record_instantiation_reporter.rb +0 -68
- data/lib/oink/base.rb +0 -40
- data/lib/oink/memory_usage_reporter.rb +0 -72
- data/lib/oink/oinked_request/oinked_ar_request.rb +0 -9
- data/lib/oink/oinked_request/oinked_memory_request.rb +0 -9
- data/lib/oink/oinked_request/oinked_request.rb +0 -16
- data/lib/oink/priority_queue.rb +0 -37
- data/spec/oink/active_record_instantiation_reporter_spec.rb +0 -191
- data/spec/oink/memory_usage_reporter_spec.rb +0 -265
- data/spec/oinked_request/oinked_request_spec.rb +0 -20
- data/spec/priority_queue/priority_queue_spec.rb +0 -75
- data/spec/rails/memory_usage_logger_spec.rb +0 -87
@@ -1,265 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
-
|
3
|
-
describe Oink::MemoryUsageReporter do
|
4
|
-
|
5
|
-
TEN_MEGS = 10 * 1024
|
6
|
-
|
7
|
-
describe "short summary with frequent offenders" do
|
8
|
-
|
9
|
-
it "should report actions which exceed the threshold once" do
|
10
|
-
str = <<-STR
|
11
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
12
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
|
13
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
14
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
15
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
|
16
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
17
|
-
STR
|
18
|
-
|
19
|
-
io = StringIO.new(str)
|
20
|
-
output = PsuedoOutput.new
|
21
|
-
Oink::MemoryUsageReporter.new(io, TEN_MEGS).print(output)
|
22
|
-
output.should include("1, MediaController#show")
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should not report actions which do not exceed the threshold" do
|
26
|
-
threshold = 10
|
27
|
-
|
28
|
-
str = <<-STR
|
29
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
30
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
|
31
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
32
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
33
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS} | PID: 4413
|
34
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
35
|
-
STR
|
36
|
-
|
37
|
-
io = StringIO.new(str)
|
38
|
-
output = PsuedoOutput.new
|
39
|
-
Oink::MemoryUsageReporter.new(io, TEN_MEGS).print(output)
|
40
|
-
output.should_not include("1, MediaController#show")
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should report actions which exceed the threshold multiple times" do
|
44
|
-
str = <<-STR
|
45
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
46
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
|
47
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
48
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
49
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
|
50
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
51
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
52
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{(TEN_MEGS * 2) + 2} | PID: 4413
|
53
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
54
|
-
STR
|
55
|
-
|
56
|
-
io = StringIO.new(str)
|
57
|
-
output = PsuedoOutput.new
|
58
|
-
Oink::MemoryUsageReporter.new(io, TEN_MEGS).print(output)
|
59
|
-
output.should include("2, MediaController#show")
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should order actions by most exceeded" do
|
63
|
-
str = <<-STR
|
64
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
65
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
|
66
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
67
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
68
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
|
69
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
70
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
71
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{(TEN_MEGS * 2) + 2} | PID: 4413
|
72
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
73
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
74
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{(TEN_MEGS * 3) + 3} | PID: 4413
|
75
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
76
|
-
STR
|
77
|
-
|
78
|
-
io = StringIO.new(str)
|
79
|
-
output = PsuedoOutput.new
|
80
|
-
Oink::MemoryUsageReporter.new(io, TEN_MEGS).print(output)
|
81
|
-
output[-2].should == "2, MediaController#show"
|
82
|
-
output[-1].should == "1, Users#show"
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should not report actions which do not complete properly" do
|
86
|
-
threshold = 10
|
87
|
-
|
88
|
-
str = <<-STR
|
89
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
90
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
|
91
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
92
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
93
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
|
94
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
95
|
-
STR
|
96
|
-
|
97
|
-
io = StringIO.new(str)
|
98
|
-
output = PsuedoOutput.new
|
99
|
-
Oink::MemoryUsageReporter.new(io, TEN_MEGS).print(output)
|
100
|
-
output.should_not include("1, MediaController#show")
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should not report actions from different pids" do
|
104
|
-
str = <<-STR
|
105
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
106
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
|
107
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
108
|
-
Feb 01 01:58:29 ey04-s00297 rails[5513]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
109
|
-
Feb 01 01:58:30 ey04-s00297 rails[5513]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
|
110
|
-
Feb 01 01:58:30 ey04-s00297 rails[5513]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
111
|
-
STR
|
112
|
-
|
113
|
-
io = StringIO.new(str)
|
114
|
-
output = PsuedoOutput.new
|
115
|
-
Oink::MemoryUsageReporter.new(io, TEN_MEGS).print(output)
|
116
|
-
output.should_not include("1, MediaController#show")
|
117
|
-
end
|
118
|
-
|
119
|
-
describe "summary with top 10 offenses" do
|
120
|
-
|
121
|
-
it "should only report requests over threshold" do
|
122
|
-
str = <<-STR
|
123
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
124
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
|
125
|
-
Feb 01 01:58:31 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
126
|
-
Feb 01 01:58:32 ey04-s00297 rails[4413]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
127
|
-
Feb 01 01:58:33 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
|
128
|
-
Feb 01 01:58:34 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
129
|
-
STR
|
130
|
-
|
131
|
-
io = StringIO.new(str)
|
132
|
-
output = PsuedoOutput.new
|
133
|
-
Oink::MemoryUsageReporter.new(io, TEN_MEGS).print(output)
|
134
|
-
output.should include("1. Feb 01 01:58:34, #{TEN_MEGS + 1} KB, MediaController#show")
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should not include requests which are not over the threshold" do
|
138
|
-
str = <<-STR
|
139
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
140
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
|
141
|
-
Feb 01 01:58:31 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
142
|
-
Feb 01 01:58:32 ey04-s00297 rails[4413]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
143
|
-
Feb 01 01:58:33 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS} | PID: 4413
|
144
|
-
Feb 01 01:58:34 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
145
|
-
STR
|
146
|
-
|
147
|
-
io = StringIO.new(str)
|
148
|
-
output = PsuedoOutput.new
|
149
|
-
Oink::MemoryUsageReporter.new(io, TEN_MEGS).print(output)
|
150
|
-
output.should_not include("1. Feb 01 01:58:34, #{TEN_MEGS + 1} KB, MediaController#show")
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should order offenses from biggest to smallest" do
|
154
|
-
str = <<-STR
|
155
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
156
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
|
157
|
-
Feb 01 01:58:31 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
158
|
-
Feb 01 01:58:32 ey04-s00297 rails[4413]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
159
|
-
Feb 01 01:58:33 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
|
160
|
-
Feb 01 01:58:34 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
161
|
-
Feb 01 01:58:35 ey04-s00297 rails[4413]: Processing DetailsController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
162
|
-
Feb 01 01:58:36 ey04-s00297 rails[4413]: Memory usage: #{(TEN_MEGS * 2) + 2} | PID: 4413
|
163
|
-
Feb 01 01:58:37 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
164
|
-
STR
|
165
|
-
|
166
|
-
io = StringIO.new(str)
|
167
|
-
output = PsuedoOutput.new
|
168
|
-
Oink::MemoryUsageReporter.new(io, TEN_MEGS).print(output)
|
169
|
-
output[4].should == "1. Feb 01 01:58:34, #{TEN_MEGS + 1} KB, MediaController#show"
|
170
|
-
output[5].should == "2. Feb 01 01:58:37, #{TEN_MEGS + 1} KB, DetailsController#show"
|
171
|
-
end
|
172
|
-
|
173
|
-
end
|
174
|
-
|
175
|
-
# it "should report the time span" do
|
176
|
-
# str = <<-STR
|
177
|
-
# Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
178
|
-
# Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
|
179
|
-
# Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
180
|
-
# Mar 13 01:58:29 ey04-s00297 rails[5513]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
181
|
-
# Mar 13 01:58:30 ey04-s00297 rails[5513]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
|
182
|
-
# Mar 13 03:58:30 ey04-s00297 rails[5513]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
183
|
-
# STR
|
184
|
-
#
|
185
|
-
# io = StringIO.new(str)
|
186
|
-
# output = PsuedoOutput.new
|
187
|
-
# Oink::MemoryUsageReporter.new(io, TEN_MEGS).each_line do |line|
|
188
|
-
# output << line
|
189
|
-
# end
|
190
|
-
# output.first.should == "Feb 01 01:58:29 - Mar 13 03:58:30"
|
191
|
-
# end
|
192
|
-
|
193
|
-
end
|
194
|
-
|
195
|
-
describe "verbose format" do
|
196
|
-
it "should print the full lines of actions exceeding the threshold" do
|
197
|
-
str = <<-STR
|
198
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
199
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Parameters: {"id"=>"2332", "controller"=>"users"}
|
200
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
|
201
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
202
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
203
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Parameters: {"id"=>"22900", "controller"=>"media"}
|
204
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
|
205
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
206
|
-
STR
|
207
|
-
io = StringIO.new(str)
|
208
|
-
output = PsuedoOutput.new
|
209
|
-
Oink::MemoryUsageReporter.new(io, TEN_MEGS, :format => :verbose).print(output)
|
210
|
-
output[3..6].should == str.split("\n")[4..7].map { |o| o.strip }
|
211
|
-
end
|
212
|
-
|
213
|
-
it "should handle actions which do not complete properly" do
|
214
|
-
threshold = 10
|
215
|
-
|
216
|
-
str = <<-STR
|
217
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
218
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
|
219
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
220
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
221
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
|
222
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
223
|
-
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]
|
224
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{(TEN_MEGS * 2) + 2} | PID: 4413
|
225
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
226
|
-
STR
|
227
|
-
|
228
|
-
io = StringIO.new(str)
|
229
|
-
output = PsuedoOutput.new
|
230
|
-
Oink::MemoryUsageReporter.new(io, TEN_MEGS, :format => :verbose).print(output)
|
231
|
-
output[3..5].should == str.split("\n")[6..8].map { |o| o.strip }
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
describe "multiple io streams" do
|
236
|
-
it "should accept multiple files" do
|
237
|
-
|
238
|
-
str1 = <<-STR
|
239
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
240
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
|
241
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
242
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
243
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
|
244
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
245
|
-
STR
|
246
|
-
|
247
|
-
str2 = <<-STR
|
248
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing Users#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
249
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: 0 | PID: 4413
|
250
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
251
|
-
Feb 01 01:58:29 ey04-s00297 rails[4413]: Processing MediaController#show (for 92.84.151.171 at 2009-02-01 01:58:29) [GET]
|
252
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Memory usage: #{TEN_MEGS + 1} | PID: 4413
|
253
|
-
Feb 01 01:58:30 ey04-s00297 rails[4413]: Completed in 984ms (View: 840, DB: 4) | 200 OK
|
254
|
-
STR
|
255
|
-
|
256
|
-
io1 = StringIO.new(str1)
|
257
|
-
io2 = StringIO.new(str2)
|
258
|
-
output = PsuedoOutput.new
|
259
|
-
Oink::MemoryUsageReporter.new([io1, io2], TEN_MEGS).print(output)
|
260
|
-
output.should include("2, MediaController#show")
|
261
|
-
end
|
262
|
-
|
263
|
-
end
|
264
|
-
|
265
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
-
|
3
|
-
describe OinkedRequest do
|
4
|
-
it "should be comparable" do
|
5
|
-
lr1 = OinkedRequest.new("Controller#Action", "February 1 10:20", [], 10)
|
6
|
-
lr2 = OinkedRequest.new("Controller#Action", "February 1 10:20", [], 5)
|
7
|
-
|
8
|
-
(lr1 > lr2).should == true
|
9
|
-
(lr1 == lr2).should == false
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should sort by memory used" do
|
13
|
-
lr1 = OinkedRequest.new("Controller#Action", "February 1 10:20", [], 10)
|
14
|
-
lr2 = OinkedRequest.new("Controller#Action", "February 1 10:20", [], 5)
|
15
|
-
lr3 = OinkedRequest.new("Controller#Action", "February 1 10:20", [], 30)
|
16
|
-
|
17
|
-
[lr1, lr2, lr3].sort.should == [lr2, lr1, lr3]
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
-
|
3
|
-
describe PriorityQueue do
|
4
|
-
|
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
|
-
|
74
|
-
|
75
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
-
|
3
|
-
class ApplicationController
|
4
|
-
attr_accessor :backtick
|
5
|
-
|
6
|
-
class Logger
|
7
|
-
attr_accessor :log
|
8
|
-
|
9
|
-
def info(*args)
|
10
|
-
(@log ||= []) << [:info, *args]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class << self
|
15
|
-
attr_accessor :after_filters
|
16
|
-
|
17
|
-
def after_filter method
|
18
|
-
(@after_filters ||= []) << method
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
include Oink::MemoryUsageLogger
|
23
|
-
|
24
|
-
def index
|
25
|
-
run_after_filters
|
26
|
-
end
|
27
|
-
|
28
|
-
def logger
|
29
|
-
@logger ||= Logger.new
|
30
|
-
end
|
31
|
-
|
32
|
-
def `(*args)
|
33
|
-
(@backtick ||= []) << args
|
34
|
-
'915'
|
35
|
-
end
|
36
|
-
|
37
|
-
protected
|
38
|
-
def run_after_filters
|
39
|
-
self.class.after_filters.each { |filter| self.send(filter) }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe Oink::MemoryUsageLogger do
|
44
|
-
unless defined? WIN32OLE
|
45
|
-
describe "get_memory_usage" do
|
46
|
-
it "should work on linux with statm" do
|
47
|
-
pages = 6271
|
48
|
-
statm_file = "#{pages} 1157 411 1 0 763 0\n"
|
49
|
-
|
50
|
-
File.should_receive(:read).with("/proc/self/statm").and_return(statm_file)
|
51
|
-
controller = ApplicationController.new
|
52
|
-
controller.should_receive(:`).with('getconf PAGESIZE').and_return("4096\n")
|
53
|
-
controller.index
|
54
|
-
controller.logger.log.should == [[:info, "Memory usage: #{pages * 4} | PID: #{$$}"]]
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should work on linux with smaps" do
|
58
|
-
proc_file = <<-STR
|
59
|
-
Header
|
60
|
-
|
61
|
-
Size: 25
|
62
|
-
Size: 13 trailing
|
63
|
-
|
64
|
-
leading Size: 4
|
65
|
-
|
66
|
-
Footer
|
67
|
-
|
68
|
-
STR
|
69
|
-
|
70
|
-
File.stub!(:read).and_raise(Errno::ENOENT.new("No such file or directory"))
|
71
|
-
File.should_receive(:new).with("/proc/#{$$}/smaps").and_return(proc_file)
|
72
|
-
controller = ApplicationController.new
|
73
|
-
controller.index
|
74
|
-
[[:info, "Memory usage: 42 | PID: #{$$}"]].should == controller.logger.log
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should work on non-linux" do
|
78
|
-
File.stub!(:read).and_raise(Errno::ENOENT.new("No such file or directory"))
|
79
|
-
File.stub!(:new).and_raise(Errno::ENOENT.new("No such file or directory"))
|
80
|
-
controller = ApplicationController.new
|
81
|
-
controller.index
|
82
|
-
[["ps -o vsz= -p #{$$}"]].should == controller.backtick
|
83
|
-
[[:info, "Memory usage: 915 | PID: #{$$}"]].should == controller.logger.log
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|