dike 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/README +184 -80
  2. data/dike-0.0.3.gem +0 -0
  3. data/gemspec.rb +2 -1
  4. data/lib/dike.rb +20 -8
  5. data/sample/a.rb +9 -0
  6. data/sample/b.rb +22 -0
  7. metadata +25 -4
data/README CHANGED
@@ -26,95 +26,193 @@ DESCRIPTION
26
26
 
27
27
  EXAMPLES
28
28
 
29
- PURE RUBY
29
+ ### PURE RUBY
30
30
 
31
- require 'dike'
31
+ ## just dumping sequential snapshots to stderr
32
32
 
33
- Dike.log STDERR # the default
33
+ # cfp:~ > cat sample/a.rb
34
+ require 'dike'
34
35
 
35
- Thread.new do
36
- sleep 4.2 and Dike.finger
37
- end
36
+ Leaks = Array.new
38
37
 
39
- Main.start
38
+ loop do
39
+ Leaks << String.new('leak' * 1024)
40
+ Dike.finger
41
+ sleep 1
42
+ end
40
43
 
41
44
 
42
- RAILS
45
+ # cfp:~ > ruby sample/a.rb | less
46
+ ...
47
+
48
+ - class: String
49
+ count: 2
50
+ trace:
51
+ - sample/a.rb:6
52
+ - sample/a.rb:5:in `loop'
53
+ - sample/a.rb:5
54
+
55
+ ...
56
+
57
+ - class: String
58
+ count: 10
59
+ trace:
60
+ - sample/a.rb:6
61
+ - sample/a.rb:5:in `loop'
62
+ - sample/a.rb:5
63
+
64
+ ...
65
+
66
+ - class: String
67
+ count: 42
68
+ trace:
69
+ - sample/a.rb:6
70
+ - sample/a.rb:5:in `loop'
71
+ - sample/a.rb:5
72
+
73
+
74
+ ## dumping sequential snapshots using Dike.logfactory and then using the 'dike'
75
+ command line tool to do comparisons of the dumped snapshots
76
+
77
+ # cfp:~ > cat sample/b.rb
78
+ require 'dike'
79
+
80
+ Leaks = Array.new
81
+
82
+ class Leak
83
+ def initialize
84
+ @leak = 42.chr * (2 ** 20)
85
+ end
86
+ end
87
+
88
+ Dike.logfactory './log/'
89
+
90
+ Dike.finger
91
+
92
+ 3.times{ Leaks << Leak.new }
93
+
94
+ Dike.finger
43
95
 
44
- file:RAILS_ROOT/config/environment.rb
96
+ 2.times{ Leaks << Leak.new }
97
+
98
+ Dike.finger
99
+
100
+ # cfp:~ > ruby sample/b.rb
101
+
102
+ # cfp:~ > ls log/
103
+ 0 1 2
104
+
105
+ # cfp:~ > dike log/
106
+ ---
107
+ - class: Leak
108
+ count: 3
109
+ trace:
110
+ - sample/b.rb:15
111
+ - sample/b.rb:15:in `times'
112
+ - sample/b.rb:15
113
+ - class: Leak
114
+ count: 2
115
+ trace:
116
+ - sample/b.rb:19
117
+ - sample/b.rb:19:in `times'
118
+ - sample/b.rb:19
119
+
120
+ # cfp:~ > dike log/0 log/1
121
+ ---
122
+ - class: Leak
123
+ count: 3
124
+ trace:
125
+ - sample/b.rb:15
126
+ - sample/b.rb:15:in `times'
127
+ - sample/b.rb:15
128
+
129
+ # cfp:~ > dike log/1 log/2
130
+ ---
131
+ - class: Leak
132
+ count: 2
133
+ trace:
134
+ - sample/b.rb:19
135
+ - sample/b.rb:19:in `times'
136
+ - sample/b.rb:19
137
+
138
+
139
+ ### RAILS
140
+
141
+ # cfp:~ > cat ./config/environment.rb
45
142
  ...
46
143
  require 'dike'
144
+ Dike.on :rails
145
+
146
+ # cfp:~ > ./script/server
147
+
148
+ # cfp:~ > curl --silent http://localhost:3000 >/dev/null
149
+
150
+ # cfp:~ > cat ./log/dike/0
151
+ ---
152
+ - class: String
153
+ count: 90769
154
+ trace: []
155
+ - class: Array
156
+ count: 18931
157
+ trace: []
158
+ - class: Class
159
+ count: 2
160
+ trace:
161
+ - votelink.com/public/../config/../lib/widgets.rb:222:in `class_factory'
162
+ - votelink.com/public/../config/../lib/widgets.rb:220:in `each'
163
+ - votelink.com/public/../config/../lib/widgets.rb:220:in `class_factory'
164
+ - votelink.com/public/../config/../lib/widgets.rb:248:in `Widget'
165
+ - votelink.com/public/../config/../lib/widgets/page/base.rb:1
166
+ - votelink.com/public/../config/../lib/widgets.rb:31:in `require'
167
+ - votelink.com/public/../config/../lib/widgets.rb:31:in `load'
168
+ - votelink.com/public/../config/../lib/widgets.rb:16:in `for_controller'
169
+ - votelink.com/public/../config/../lib/widgets.rb:243:in `widget'
170
+ - votelink.com/public/../config/../app/controllers/application.rb:150
171
+ ...
172
+
173
+ # cfp:~ > curl --silent http://localhost:3000 >/dev/null
174
+
175
+ # cfp:~ > cat ./log/dike/1
176
+ ---
177
+ - class: String
178
+ count: 100769
179
+ trace: []
180
+ - class: Array
181
+ count: 19931
182
+ trace: []
183
+ - class: Class
184
+ count: 5
185
+ trace:
186
+ - votelink.com/public/../config/../lib/widgets.rb:222:in `class_factory'
187
+ - votelink.com/public/../config/../lib/widgets.rb:220:in `each'
188
+ - votelink.com/public/../config/../lib/widgets.rb:220:in `class_factory'
189
+ - votelink.com/public/../config/../lib/widgets.rb:248:in `Widget'
190
+ - votelink.com/public/../config/../lib/widgets/page/base.rb:1
191
+ - votelink.com/public/../config/../lib/widgets.rb:31:in `require'
192
+ - votelink.com/public/../config/../lib/widgets.rb:31:in `load'
193
+ - votelink.com/public/../config/../lib/widgets.rb:16:in `for_controller'
194
+ - votelink.com/public/../config/../lib/widgets.rb:243:in `widget'
195
+ - votelink.com/public/../config/../app/controllers/application.rb:150
196
+ ...
197
+
198
+ # cfp:~ > dike ./log/dike
199
+ ...
200
+ - class: Class
201
+ count: 3
202
+ trace:
203
+ - votelink.com/public/../config/../lib/widgets.rb:222:in `class_factory'
204
+ - votelink.com/public/../config/../lib/widgets.rb:220:in `each'
205
+ - votelink.com/public/../config/../lib/widgets.rb:220:in `class_factory'
206
+ - votelink.com/public/../config/../lib/widgets.rb:248:in `Widget'
207
+ - votelink.com/public/../config/../lib/widgets/page/base.rb:1
208
+ - votelink.com/public/../config/../lib/widgets.rb:31:in `require'
209
+ - votelink.com/public/../config/../lib/widgets.rb:31:in `load'
210
+ - votelink.com/public/../config/../lib/widgets.rb:16:in `for_controller'
211
+ - votelink.com/public/../config/../lib/widgets.rb:243:in `widget'
212
+ - votelink.com/public/../config/../app/controllers/application.rb:150
213
+ ...
47
214
 
48
- shell: ./script/server
49
-
50
- shell: curl --silent http://localhost:3000 >/dev/null
51
-
52
- shell: cat ./log/dike/0
53
- ---
54
- - class: String
55
- count: 90769
56
- trace: []
57
- - class: Array
58
- count: 18931
59
- trace: []
60
- - class: Class
61
- count: 2
62
- trace:
63
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:222:in `class_factory'
64
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:220:in `each'
65
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:220:in `class_factory'
66
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:248:in `Widget'
67
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets/page/base.rb:1
68
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:31:in `require'
69
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:31:in `load'
70
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:16:in `for_controller'
71
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:243:in `widget'
72
- - /Users/ahoward/site/votelink.com/public/../config/../app/controllers/application.rb:150
73
- ...
74
-
75
- shell: curl --silent http://localhost:3000 >/dev/null
76
-
77
- shell: cat ./log/dike/1
78
- ---
79
- - class: String
80
- count: 100769
81
- trace: []
82
- - class: Array
83
- count: 19931
84
- trace: []
85
- - class: Class
86
- count: 5
87
- trace:
88
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:222:in `class_factory'
89
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:220:in `each'
90
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:220:in `class_factory'
91
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:248:in `Widget'
92
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets/page/base.rb:1
93
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:31:in `require'
94
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:31:in `load'
95
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:16:in `for_controller'
96
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:243:in `widget'
97
- - /Users/ahoward/site/votelink.com/public/../config/../app/controllers/application.rb:150
98
- ...
99
-
100
- shell: dike ./log/dike
101
- ...
102
- - class: Class
103
- count: 3
104
- trace:
105
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:222:in `class_factory'
106
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:220:in `each'
107
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:220:in `class_factory'
108
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:248:in `Widget'
109
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets/page/base.rb:1
110
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:31:in `require'
111
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:31:in `load'
112
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:16:in `for_controller'
113
- - /Users/ahoward/site/votelink.com/public/../config/../lib/widgets.rb:243:in `widget'
114
- - /Users/ahoward/site/votelink.com/public/../config/../app/controllers/application.rb:150
115
- ...
116
-
117
- SUMMARY
215
+ NOTES
118
216
 
119
217
  * the 'Dike.finger' method dumps it's log in a format showing
120
218
 
@@ -170,7 +268,13 @@ SUMMARY
170
268
 
171
269
  LIMITATIONS
172
270
 
173
- not all object creation can be tracked and not all leaks are reported.
271
+ not all object creation can be tracked. not all leaks are reported. some
272
+ reported leaks are not. dike shows you where in the source objects are being
273
+ created that cannot be reclaimed - these are not always leaks as this line
274
+
275
+ class C; end
276
+
277
+ shows. the class 'C' cannot be reclaimed and is not a leak.
174
278
 
175
279
  AUTHOR
176
280
 
File without changes
data/gemspec.rb CHANGED
@@ -18,7 +18,8 @@ Gem::Specification::new do |spec|
18
18
 
19
19
  spec.has_rdoc = File::exist? "doc"
20
20
  spec.test_suite_file = "test/#{ lib }.rb" if File::directory? "test"
21
- #spec.add_dependency 'lib', '>= version'
21
+ spec.add_dependency 'attributes', '>= 3.6.0'
22
+ spec.add_dependency 'orderedhash', '>= 0.0.2'
22
23
 
23
24
  spec.extensions << "extconf.rb" if File::exists? "extconf.rb"
24
25
 
@@ -29,8 +29,8 @@ module Dike
29
29
  Objects = Hash.new
30
30
 
31
31
  def mark_birth object, stacktrace
32
- return if Objects[object_id]
33
32
  object_id = Object::Methods["object_id"].bind(object).call
33
+ return if Objects[object_id]
34
34
  Objects[object_id] = stacktrace
35
35
  ObjectSpace.define_finalizer object, &mark_birth_finalizer(object_id)
36
36
  end
@@ -78,12 +78,17 @@ module Dike
78
78
  attribute("threshold"){ Struct.new(:class, :code, :object)[42, 42, 1] }
79
79
  attribute("log"){ STDERR }
80
80
  attribute("logfactory"){ nil }
81
+
82
+ def logfactory= value
83
+ @logfactory =
84
+ LogFactory === value ? value : LogFactory.new(value)
85
+ end
81
86
 
82
87
  def finger options = {}
83
88
  Thread.critical = true
84
89
 
85
90
  begin
86
- GC.start
91
+ 42.times{ GC.start }
87
92
 
88
93
  count, code = :remembered
89
94
 
@@ -253,12 +258,19 @@ end
253
258
 
254
259
 
255
260
  if defined? Rails
256
- Dike.logfactory Dike::LogFactory.new(File.join(RAILS_ROOT, "log", "dike"))
257
-
258
- ActionController::Base.module_eval do
259
- after_filter do |controller|
260
- Dike.finger
261
- true
261
+ module Dike
262
+ def self.on which = :rails
263
+ case which.to_s
264
+ when %r/^rails$/i
265
+ Dike.logfactory File.join(RAILS_ROOT, "log", "dike")
266
+
267
+ ActionController::Base.module_eval do
268
+ after_filter do |controller|
269
+ Dike.finger
270
+ true
271
+ end
272
+ end
273
+ end
262
274
  end
263
275
  end
264
276
  end
@@ -0,0 +1,9 @@
1
+ require 'dike'
2
+
3
+ Leaks = Array.new
4
+
5
+ loop do
6
+ Leaks << String.new('leak' * 1024)
7
+ Dike.finger
8
+ sleep 1
9
+ end
@@ -0,0 +1,22 @@
1
+ require 'dike'
2
+
3
+ Leaks = Array.new
4
+
5
+ class Leak
6
+ def initialize
7
+ @leak = 42.chr * (2 ** 20)
8
+ end
9
+ end
10
+
11
+ Dike.logfactory './log/'
12
+
13
+ Dike.finger
14
+
15
+ 3.times{ Leaks << Leak.new }
16
+
17
+ Dike.finger
18
+
19
+ 2.times{ Leaks << Leak.new }
20
+
21
+ Dike.finger
22
+
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: dike
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.2
7
- date: 2007-09-27 00:00:00 -06:00
6
+ version: 0.0.3
7
+ date: 2007-09-29 00:00:00 -06:00
8
8
  summary: dike
9
9
  require_paths:
10
10
  - lib
@@ -31,11 +31,15 @@ authors:
31
31
  files:
32
32
  - bin
33
33
  - bin/dike
34
+ - dike-0.0.3.gem
34
35
  - gemspec.rb
35
36
  - install.rb
36
37
  - lib
37
38
  - lib/dike.rb
38
39
  - README
40
+ - sample
41
+ - sample/a.rb
42
+ - sample/b.rb
39
43
  test_files: []
40
44
 
41
45
  rdoc_options: []
@@ -48,5 +52,22 @@ extensions: []
48
52
 
49
53
  requirements: []
50
54
 
51
- dependencies: []
52
-
55
+ dependencies:
56
+ - !ruby/object:Gem::Dependency
57
+ name: attributes
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Version::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 3.6.0
64
+ version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: orderedhash
67
+ version_requirement:
68
+ version_requirements: !ruby/object:Gem::Version::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 0.0.2
73
+ version: