ssoroka-bleak_house 4.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +53 -0
- data/LICENSE +184 -0
- data/LICENSE_BSD +10 -0
- data/Manifest +24 -0
- data/README +119 -0
- data/Rakefile +13 -0
- data/TODO +8 -0
- data/bin/bleak +13 -0
- data/bleak_house.gemspec +36 -0
- data/ext/build_ruby.rb +106 -0
- data/ext/build_snapshot.rb +4 -0
- data/ext/extconf.rb +3 -0
- data/ext/snapshot.c +150 -0
- data/ext/snapshot.h +59 -0
- data/lib/bleak_house/analyzer.rb +54 -0
- data/lib/bleak_house/hook.rb +25 -0
- data/lib/bleak_house.rb +7 -0
- data/ruby/configure.patch +242 -0
- data/ruby/gc.patch +119 -0
- data/ruby/ruby-1.8.6-p230.tar.bz2 +0 -0
- data/ruby/valgrind.patch +123 -0
- data/test/benchmark/bench.rb +16 -0
- data/test/test_helper.rb +6 -0
- data/test/unit/test_bleak_house.rb +52 -0
- metadata +99 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
v4.1.1. Update bundled Ruby to patchlevel 230.
|
3
|
+
|
4
|
+
v4.1. Support calculating deltas in analyze utility.
|
5
|
+
|
6
|
+
v4.0. Track spawn points live instead of sampling.
|
7
|
+
|
8
|
+
v3.7.1. Fix some nil issues with corrupted dumps (cody caughlan).
|
9
|
+
|
10
|
+
v3.7. Sample object contents. Restore Rails 1.2.x compatibility.
|
11
|
+
|
12
|
+
v3.6. Rails 2.0.2 compatibility.
|
13
|
+
|
14
|
+
v3.5.1. Update bundled Ruby to patchlevel 110.
|
15
|
+
|
16
|
+
v3.5. Explain when you need more frames. Use a cross-platform version of 'which'. Slight accuracy improvement.
|
17
|
+
|
18
|
+
v3.4. Clearer output descriptions; work around a Marshal bug on x64; fix for missing immortal leaks.
|
19
|
+
|
20
|
+
v3.3. Build Ruby in gem install step; bundle Ruby 1.8.6 source; fixes for truncated final frames.
|
21
|
+
|
22
|
+
v3.2. Use Ccsv for faster parsing.
|
23
|
+
|
24
|
+
v3.0.3. Caching; build task; impact factor.
|
25
|
+
|
26
|
+
v3.0.1. Rewrite. Remove Gruffs and graphs. Become a standard compiled extension. Walk the symbol table. Track object histories. Use custom CSV format instead of YAML.
|
27
|
+
|
28
|
+
v2.7. Version renumbering; apologies if this messes anyone up.
|
29
|
+
|
30
|
+
v2.6. RDoc documentation; use new Echoe setup; fix for namespaced controllers.
|
31
|
+
|
32
|
+
v2.5. Detect if core keys are present or not; fixes for analyzing non-Rails apps.
|
33
|
+
|
34
|
+
v2.4. Log heap usage; remove pure-Ruby profiler.
|
35
|
+
|
36
|
+
v2.3. Subtract Rails core counts from action counts and join paired frames.
|
37
|
+
|
38
|
+
v2.2. Change smoothing algorithm to be more intuitive and so mem usage is correct.
|
39
|
+
|
40
|
+
v2.1. Close file properly.
|
41
|
+
|
42
|
+
v2. C instrumentation with YAML output.
|
43
|
+
|
44
|
+
v1.3. Log memory usage on *nix.
|
45
|
+
|
46
|
+
v1.2. Fix nil directory traversal error on Windows.
|
47
|
+
|
48
|
+
v1.1. Gem version
|
49
|
+
|
50
|
+
v1. Dumped Rublique; replaced with a lightweight non-delta marshalling version.
|
51
|
+
|
52
|
+
v0. First version
|
53
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
Academic Free License (AFL) v. 3.0
|
2
|
+
|
3
|
+
This Academic Free License (the "License") applies to any original work
|
4
|
+
of authorship (the "Original Work") whose owner (the "Licensor") has
|
5
|
+
placed the following licensing notice adjacent to the copyright notice
|
6
|
+
for the Original Work:
|
7
|
+
|
8
|
+
Licensed under the Academic Free License version 3.0
|
9
|
+
|
10
|
+
1) Grant of Copyright License. Licensor grants You a worldwide,
|
11
|
+
royalty-free, non-exclusive, sublicensable license, for the duration of
|
12
|
+
the copyright, to do the following:
|
13
|
+
|
14
|
+
a) to reproduce the Original Work in copies, either alone or as part of
|
15
|
+
a collective work;
|
16
|
+
|
17
|
+
b) to translate, adapt, alter, transform, modify, or arrange the
|
18
|
+
Original Work, thereby creating derivative works ("Derivative Works")
|
19
|
+
based upon the Original Work;
|
20
|
+
|
21
|
+
c) to distribute or communicate copies of the Original Work and
|
22
|
+
Derivative Works to the public, under any license of your choice that
|
23
|
+
does not contradict the terms and conditions, including Licensor's
|
24
|
+
reserved rights and remedies, in this Academic Free License;
|
25
|
+
|
26
|
+
d) to perform the Original Work publicly; and
|
27
|
+
|
28
|
+
e) to display the Original Work publicly.
|
29
|
+
|
30
|
+
2) Grant of Patent License. Licensor grants You a worldwide,
|
31
|
+
royalty-free, non-exclusive, sublicensable license, under patent claims
|
32
|
+
owned or controlled by the Licensor that are embodied in the Original
|
33
|
+
Work as furnished by the Licensor, for the duration of the patents, to
|
34
|
+
make, use, sell, offer for sale, have made, and import the Original Work
|
35
|
+
and Derivative Works.
|
36
|
+
|
37
|
+
3) Grant of Source Code License. The term "Source Code" means the
|
38
|
+
preferred form of the Original Work for making modifications to it and
|
39
|
+
all available documentation describing how to modify the Original Work.
|
40
|
+
Licensor agrees to provide a machine-readable copy of the Source Code of
|
41
|
+
the Original Work along with each copy of the Original Work that
|
42
|
+
Licensor distributes. Licensor reserves the right to satisfy this
|
43
|
+
obligation by placing a machine-readable copy of the Source Code in an
|
44
|
+
information repository reasonably calculated to permit inexpensive and
|
45
|
+
convenient access by You for as long as Licensor continues to distribute
|
46
|
+
the Original Work.
|
47
|
+
|
48
|
+
4) Exclusions From License Grant. Neither the names of Licensor, nor the
|
49
|
+
names of any contributors to the Original Work, nor any of their
|
50
|
+
trademarks or service marks, may be used to endorse or promote products
|
51
|
+
derived from this Original Work without express prior permission of the
|
52
|
+
Licensor. Except as expressly stated herein, nothing in this License
|
53
|
+
grants any license to Licensor's trademarks, copyrights, patents, trade
|
54
|
+
secrets or any other intellectual property. No patent license is granted
|
55
|
+
to make, use, sell, offer for sale, have made, or import embodiments of
|
56
|
+
any patent claims other than the licensed claims defined in Section 2.
|
57
|
+
No license is granted to the trademarks of Licensor even if such marks
|
58
|
+
are included in the Original Work. Nothing in this License shall be
|
59
|
+
interpreted to prohibit Licensor from licensing under terms different
|
60
|
+
from this License any Original Work that Licensor otherwise would have a
|
61
|
+
right to license.
|
62
|
+
|
63
|
+
5) External Deployment. The term "External Deployment" means the use,
|
64
|
+
distribution, or communication of the Original Work or Derivative Works
|
65
|
+
in any way such that the Original Work or Derivative Works may be used
|
66
|
+
by anyone other than You, whether those works are distributed or
|
67
|
+
communicated to those persons or made available as an application
|
68
|
+
intended for use over a network. As an express condition for the grants
|
69
|
+
of license hereunder, You must treat any External Deployment by You of
|
70
|
+
the Original Work or a Derivative Work as a distribution under section
|
71
|
+
1(c).
|
72
|
+
|
73
|
+
6) Attribution Rights. You must retain, in the Source Code of any
|
74
|
+
Derivative Works that You create, all copyright, patent, or trademark
|
75
|
+
notices from the Source Code of the Original Work, as well as any
|
76
|
+
notices of licensing and any descriptive text identified therein as an
|
77
|
+
"Attribution Notice." You must cause the Source Code for any Derivative
|
78
|
+
Works that You create to carry a prominent Attribution Notice reasonably
|
79
|
+
calculated to inform recipients that You have modified the Original
|
80
|
+
Work.
|
81
|
+
|
82
|
+
7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants
|
83
|
+
that the copyright in and to the Original Work and the patent rights
|
84
|
+
granted herein by Licensor are owned by the Licensor or are sublicensed
|
85
|
+
to You under the terms of this License with the permission of the
|
86
|
+
contributor(s) of those copyrights and patent rights. Except as
|
87
|
+
expressly stated in the immediately preceding sentence, the Original
|
88
|
+
Work is provided under this License on an "AS IS" BASIS and WITHOUT
|
89
|
+
WARRANTY, either express or implied, including, without limitation, the
|
90
|
+
warranties of non-infringement, merchantability or fitness for a
|
91
|
+
particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL
|
92
|
+
WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential
|
93
|
+
part of this License. No license to the Original Work is granted by this
|
94
|
+
License except under this disclaimer.
|
95
|
+
|
96
|
+
8) Limitation of Liability. Under no circumstances and under no legal
|
97
|
+
theory, whether in tort (including negligence), contract, or otherwise,
|
98
|
+
shall the Licensor be liable to anyone for any indirect, special,
|
99
|
+
incidental, or consequential damages of any character arising as a
|
100
|
+
result of this License or the use of the Original Work including,
|
101
|
+
without limitation, damages for loss of goodwill, work stoppage,
|
102
|
+
computer failure or malfunction, or any and all other commercial damages
|
103
|
+
or losses. This limitation of liability shall not apply to the extent
|
104
|
+
applicable law prohibits such limitation.
|
105
|
+
|
106
|
+
9) Acceptance and Termination. If, at any time, You expressly assented
|
107
|
+
to this License, that assent indicates your clear and irrevocable
|
108
|
+
acceptance of this License and all of its terms and conditions. If You
|
109
|
+
distribute or communicate copies of the Original Work or a Derivative
|
110
|
+
Work, You must make a reasonable effort under the circumstances to
|
111
|
+
obtain the express assent of recipients to the terms of this License.
|
112
|
+
This License conditions your rights to undertake the activities listed
|
113
|
+
in Section 1, including your right to create Derivative Works based upon
|
114
|
+
the Original Work, and doing so without honoring these terms and
|
115
|
+
conditions is prohibited by copyright law and international treaty.
|
116
|
+
Nothing in this License is intended to affect copyright exceptions and
|
117
|
+
limitations (including "fair use" or "fair dealing"). This License shall
|
118
|
+
terminate immediately and You may no longer exercise any of the rights
|
119
|
+
granted to You by this License upon your failure to honor the conditions
|
120
|
+
in Section 1(c).
|
121
|
+
|
122
|
+
10) Termination for Patent Action. This License shall terminate
|
123
|
+
automatically and You may no longer exercise any of the rights granted
|
124
|
+
to You by this License as of the date You commence an action, including
|
125
|
+
a cross-claim or counterclaim, against Licensor or any licensee alleging
|
126
|
+
that the Original Work infringes a patent. This termination provision
|
127
|
+
shall not apply for an action alleging patent infringement by
|
128
|
+
combinations of the Original Work with other software or hardware.
|
129
|
+
|
130
|
+
11) Jurisdiction, Venue and Governing Law. Any action or suit relating
|
131
|
+
to this License may be brought only in the courts of a jurisdiction
|
132
|
+
wherein the Licensor resides or in which Licensor conducts its primary
|
133
|
+
business, and under the laws of that jurisdiction excluding its
|
134
|
+
conflict-of-law provisions. The application of the United Nations
|
135
|
+
Convention on Contracts for the International Sale of Goods is expressly
|
136
|
+
excluded. Any use of the Original Work outside the scope of this License
|
137
|
+
or after its termination shall be subject to the requirements and
|
138
|
+
penalties of copyright or patent law in the appropriate jurisdiction.
|
139
|
+
This section shall survive the termination of this License.
|
140
|
+
|
141
|
+
12) Attorneys' Fees. In any action to enforce the terms of this License
|
142
|
+
or seeking damages relating thereto, the prevailing party shall be
|
143
|
+
entitled to recover its costs and expenses, including, without
|
144
|
+
limitation, reasonable attorneys' fees and costs incurred in connection
|
145
|
+
with such action, including any appeal of such action. This section
|
146
|
+
shall survive the termination of this License.
|
147
|
+
|
148
|
+
13) Miscellaneous. If any provision of this License is held to be
|
149
|
+
unenforceable, such provision shall be reformed only to the extent
|
150
|
+
necessary to make it enforceable.
|
151
|
+
|
152
|
+
14) Definition of "You" in This License. "You" throughout this License,
|
153
|
+
whether in upper or lower case, means an individual or a legal entity
|
154
|
+
exercising rights under, and complying with all of the terms of, this
|
155
|
+
License. For legal entities, "You" includes any entity that controls, is
|
156
|
+
controlled by, or is under common control with you. For purposes of this
|
157
|
+
definition, "control" means (i) the power, direct or indirect, to cause
|
158
|
+
the direction or management of such entity, whether by contract or
|
159
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
160
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
161
|
+
|
162
|
+
15) Right to Use. You may use the Original Work in all ways not
|
163
|
+
otherwise restricted or conditioned by this License or by law, and
|
164
|
+
Licensor promises not to interfere with or be responsible for such uses
|
165
|
+
by You.
|
166
|
+
|
167
|
+
16) Modification of This License. This License is Copyright (c) 2005
|
168
|
+
Lawrence Rosen. Permission is granted to copy, distribute, or
|
169
|
+
communicate this License without modification. Nothing in this License
|
170
|
+
permits You to modify this License as applied to the Original Work or to
|
171
|
+
Derivative Works. However, You may modify the text of this License and
|
172
|
+
copy, distribute or communicate your modified version (the "Modified
|
173
|
+
License") and apply it to other original works of authorship subject to
|
174
|
+
the following conditions: (i) You may not indicate in any way that your
|
175
|
+
Modified License is the "Academic Free License" or "AFL" and you may not
|
176
|
+
use those names in the name of your Modified License; (ii) You must
|
177
|
+
replace the notice specified in the first paragraph above with the
|
178
|
+
notice "Licensed under <insert your license name here>" or with a notice
|
179
|
+
of your own that is not confusingly similar to the notice in this
|
180
|
+
License; and (iii) You may not claim that your original works are open
|
181
|
+
source software unless your Modified License has been approved by Open
|
182
|
+
Source Initiative (OSI) and You comply with its license review and
|
183
|
+
certification process.
|
184
|
+
|
data/LICENSE_BSD
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
Copyright 2006, Eric Hodel. All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
5
|
+
|
6
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
8
|
+
3. Neither the names of the authors nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
9
|
+
|
10
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS?? AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/Manifest
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
bin/bleak
|
2
|
+
bleak_house.gemspec
|
3
|
+
CHANGELOG
|
4
|
+
ext/build_ruby.rb
|
5
|
+
ext/build_snapshot.rb
|
6
|
+
ext/extconf.rb
|
7
|
+
ext/snapshot.c
|
8
|
+
ext/snapshot.h
|
9
|
+
lib/bleak_house/analyzer.rb
|
10
|
+
lib/bleak_house/hook.rb
|
11
|
+
lib/bleak_house.rb
|
12
|
+
LICENSE
|
13
|
+
LICENSE_BSD
|
14
|
+
Manifest
|
15
|
+
Rakefile
|
16
|
+
README
|
17
|
+
ruby/configure.patch
|
18
|
+
ruby/gc.patch
|
19
|
+
ruby/ruby-1.8.6-p230.tar.bz2
|
20
|
+
ruby/valgrind.patch
|
21
|
+
test/benchmark/bench.rb
|
22
|
+
test/test_helper.rb
|
23
|
+
test/unit/test_bleak_house.rb
|
24
|
+
TODO
|
data/README
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
|
2
|
+
BleakHouse
|
3
|
+
|
4
|
+
A library for finding memory leaks.
|
5
|
+
|
6
|
+
== License
|
7
|
+
|
8
|
+
Copyright 2007, 2008 Cloudburst, LLC. Licensed under the AFL 3. See the included LICENSE file. Portions copyright 2006 Eric Hodel and used with permission. See the included LICENSE_BSD file.
|
9
|
+
|
10
|
+
The public certificate for this gem is here[http://rubyforge.org/frs/download.php/25331/evan_weaver-original-public_cert.pem].
|
11
|
+
|
12
|
+
If you use this software, please {make a donation}[http://blog.evanweaver.com/donate/], or {recommend Evan}[http://www.workingwithrails.com/person/7739-evan-weaver] at Working with Rails.
|
13
|
+
|
14
|
+
== Features
|
15
|
+
|
16
|
+
* leak-proof C instrumentation
|
17
|
+
* minimal impact on runtime performance
|
18
|
+
* fast analysis step
|
19
|
+
* tracks all objects allocated on the heap, including internal types like <tt>T_NODE</tt>
|
20
|
+
* easy integration into any program, not just Rails
|
21
|
+
|
22
|
+
== Requirements
|
23
|
+
|
24
|
+
* A unix-like operating system
|
25
|
+
* Ruby 1.8.6
|
26
|
+
|
27
|
+
= Usage
|
28
|
+
|
29
|
+
== Installation
|
30
|
+
|
31
|
+
Install the gem:
|
32
|
+
sudo gem install bleak_house
|
33
|
+
|
34
|
+
The installation takes a long time because it compiles a patched Ruby binary for you. It is installed as <tt>ruby-bleak-house</tt> alongside your regular <tt>ruby</tt> binary.
|
35
|
+
|
36
|
+
Please see the forum ( http://rubyforge.org/forum/forum.php?forum_id=13983 ) if you have installation problems.
|
37
|
+
|
38
|
+
== Usage
|
39
|
+
|
40
|
+
We will profile a Rails app as an example. Note that BleakHouse works equally well in any Ruby program.
|
41
|
+
|
42
|
+
First, to setup the app for profiling, add the following at the bottom of <tt>config/environment.rb</tt>:
|
43
|
+
require 'bleak_house' if ENV['BLEAK_HOUSE']
|
44
|
+
|
45
|
+
Then, to engage the logger (possibly in a live deployment situation), start a server instance as so:
|
46
|
+
RAILS_ENV=production BLEAK_HOUSE=1 ruby-bleak-house ./script/server
|
47
|
+
|
48
|
+
Look for the message:
|
49
|
+
** Bleakhouse: installed
|
50
|
+
|
51
|
+
Exercise your app. After a couple hundred requests, hit CTRL-C. The server will stop and BleakHouse will produce a dumpfile in <tt>/tmp</tt>:
|
52
|
+
|
53
|
+
** BleakHouse: working...
|
54
|
+
** BleakHouse: complete
|
55
|
+
** Bleakhouse: run 'bleak /tmp/bleak.5979.0.dump' to analyze.
|
56
|
+
|
57
|
+
To analyze it, just run the listed command. The top 20 leakiest lines will be listed:
|
58
|
+
|
59
|
+
191691 total objects
|
60
|
+
Final heap size 191691 filled, 220961 free
|
61
|
+
Displaying top 20 most common line/class pairs
|
62
|
+
89513 __null__:__null__:__node__
|
63
|
+
41438 __null__:__null__:String
|
64
|
+
2348 /opt/local//lib/ruby/site_ruby/1.8/rubygems/specification.rb:557:Array
|
65
|
+
1508 /opt/local//lib/ruby/gems/1.8/specifications/gettext-1.90.0.gemspec:14:String
|
66
|
+
1021 /opt/local//lib/ruby/gems/1.8/specifications/heel-0.2.0.gemspec:14:String
|
67
|
+
951 /opt/local//lib/ruby/site_ruby/1.8/rubygems/version.rb:111:String
|
68
|
+
935 /opt/local//lib/ruby/site_ruby/1.8/rubygems/specification.rb:557:String
|
69
|
+
834 /opt/local//lib/ruby/site_ruby/1.8/rubygems/version.rb:146:Array
|
70
|
+
...
|
71
|
+
|
72
|
+
You can pass an integer as the second parameter to <tt>bleak</tt> if you want to see more lines than the default.
|
73
|
+
|
74
|
+
The underscored types are special Ruby internal structs, but can be real leaks just as easily as fullblown classes.
|
75
|
+
|
76
|
+
= Extras
|
77
|
+
|
78
|
+
== Injecting a signal
|
79
|
+
|
80
|
+
You can send <tt>SIGUSR2</tt> to a BleakHouse-instrumented program to snag a dump at any time. Once the dump completes, the program will continue to run. Dumps are named based on the host process id, and sequential dumps are numbered in ascending order.
|
81
|
+
|
82
|
+
== Tips
|
83
|
+
|
84
|
+
Do not try to detect Rails leaks in <tt>development</tt> mode. Make a separate <tt>benchmark</tt> environment if you need to, and make sure all your production caching is turned on.
|
85
|
+
|
86
|
+
It is normal to see lots of <tt>null:null</tt> references, especially for nodes. Using <tt>eval()</tt> too much can be a cause of node leaks. You can track <tt>eval()</tt> by using sourceline macros in your code:
|
87
|
+
|
88
|
+
eval("CODE", nil, __FILE__, __LINE__)
|
89
|
+
|
90
|
+
You may get library require errors if you install <tt>ruby-bleak-house</tt> 1.8.6 alongside a different verson of Ruby. You could try to patch your local version of Ruby instead, or you could just upgrade to 1.8.6, which has a good trackrecord of stability.
|
91
|
+
|
92
|
+
It is not recommended that you use <tt>ruby-bleak-house</tt> as your production Ruby binary, since it will be slightly slower and use slightly more memory. It is unlikely, however, to affect stability.
|
93
|
+
|
94
|
+
If BleakHouse doesn't report any heap growth but you still have memory growth, you might have a broken C extension, or have encounted a {real leak in the interpreter}[http://groups.google.com/group/god-rb/browse_thread/thread/01cca2b7c4a581c2]. Try using Valgrind[http://blog.evanweaver.com/articles/2008/02/05/valgrind-and-ruby/] instead.
|
95
|
+
|
96
|
+
== Methods
|
97
|
+
|
98
|
+
The easiest way to fix a leak is to make it repeatable.
|
99
|
+
|
100
|
+
First, write a script that exercises your app in a deterministic way. Run it for a small number of loops; then run <tt>bleak</tt>. Then run it for a larger number of loops, and run <tt>bleak</tt> again. The lines that grow significantly between runs are your leaks for that codepath.
|
101
|
+
|
102
|
+
Now, look at those lines in the source and try to figure out what references them. Where do the return values go? Add some breakpoints or output backtraces to <tt>STDERR</tt> as you go. Eventually you should find a point where it is relatively clear that a reference is getting maintained.
|
103
|
+
|
104
|
+
Try to remove that reference, run your script again, and see if the object counts have dropped.
|
105
|
+
|
106
|
+
== Reporting problems
|
107
|
+
|
108
|
+
The support forum is here[http://rubyforge.org/forum/forum.php?forum_id=13983].
|
109
|
+
|
110
|
+
Patches and contributions are very welcome. Please note that contributors are required to assign copyright for their additions to Cloudburst, LLC.
|
111
|
+
|
112
|
+
== Further resources
|
113
|
+
|
114
|
+
* http://blog.evanweaver.com/articles/2008/04/06/bleakhouse-4/
|
115
|
+
* http://blog.evanweaver.com/articles/2008/02/05/valgrind-and-ruby/
|
116
|
+
* http://blog.evanweaver.com/articles/2007/05/12/let-me-hit-you-with-some-knowledge
|
117
|
+
* http://blog.evanweaver.com/articles/2007/05/06/leak-proof-direct-heap-instrumentation-for-bleak_house
|
118
|
+
* http://blog.evanweaver.com/articles/2007/04/28/bleak_house
|
119
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
require 'echoe'
|
3
|
+
|
4
|
+
Echoe.new("bleak_house") do |p|
|
5
|
+
p.author = "Evan Weaver"
|
6
|
+
p.email = ''
|
7
|
+
p.project = "fauna"
|
8
|
+
p.summary = "A library for finding memory leaks."
|
9
|
+
p.url = "http://blog.evanweaver.com/files/doc/fauna/bleak_house/"
|
10
|
+
p.docs_host = 'blog.evanweaver.com:~/www/bax/public/files/doc/'
|
11
|
+
p.require_signed = false
|
12
|
+
p.rdoc_pattern = /^ext.*\.c|lib.*|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
|
13
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
|
2
|
+
* Override Kernel#eval to always include sourceline macros.
|
3
|
+
* Mimic Valgrind's output format as much as possible
|
4
|
+
* Log remaining heap reference traces
|
5
|
+
* Add some kind of start/end delta support
|
6
|
+
* Log entire backtrace by allocating pointer arrays on the heap
|
7
|
+
- Add some kind of hashing procedure to avoid duplicating identical backtrace pointer arrays
|
8
|
+
* Report individual types of nodes
|
data/bin/bleak
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
if !ARGV[0]
|
6
|
+
puts "Please specify up to two BleakHouse logfiles"
|
7
|
+
exit
|
8
|
+
else
|
9
|
+
$LOAD_PATH << "#{File.dirname(__FILE__)}/../lib/"
|
10
|
+
require 'bleak_house/analyzer'
|
11
|
+
require 'ruby-debug' if ENV['DEBUG']
|
12
|
+
BleakHouse::Analyzer.run(*ARGV)
|
13
|
+
end
|
data/bleak_house.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{bleak_house}
|
3
|
+
s.version = "4.1.1"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Evan Weaver"]
|
7
|
+
s.date = %q{2008-12-01}
|
8
|
+
s.default_executable = %q{bleak}
|
9
|
+
s.description = %q{A library for finding memory leaks.}
|
10
|
+
s.email = %q{}
|
11
|
+
s.executables = ["bleak"]
|
12
|
+
s.extensions = ["ext/extconf.rb"]
|
13
|
+
s.extra_rdoc_files = ["CHANGELOG", "ext/snapshot.c", "lib/bleak_house/analyzer.rb", "lib/bleak_house/hook.rb", "lib/bleak_house.rb", "LICENSE", "LICENSE_BSD", "README", "TODO"]
|
14
|
+
s.files = ["bin/bleak", "bleak_house.gemspec", "CHANGELOG", "ext/build_ruby.rb", "ext/build_snapshot.rb", "ext/extconf.rb", "ext/snapshot.c", "ext/snapshot.h", "lib/bleak_house/analyzer.rb", "lib/bleak_house/hook.rb", "lib/bleak_house.rb", "LICENSE", "LICENSE_BSD", "Manifest", "Rakefile", "README", "ruby/configure.patch", "ruby/gc.patch", "ruby/ruby-1.8.6-p230.tar.bz2", "ruby/valgrind.patch", "test/benchmark/bench.rb", "test/test_helper.rb", "test/unit/test_bleak_house.rb", "TODO"]
|
15
|
+
s.has_rdoc = true
|
16
|
+
s.homepage = %q{http://blog.evanweaver.com/files/doc/fauna/bleak_house/}
|
17
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Bleak_house", "--main", "README"]
|
18
|
+
s.require_paths = ["lib", "ext"]
|
19
|
+
s.rubyforge_project = %q{fauna}
|
20
|
+
s.rubygems_version = %q{1.2.0}
|
21
|
+
s.summary = %q{A library for finding memory leaks.}
|
22
|
+
s.test_files = ["test/test_helper.rb", "test/unit/test_bleak_house.rb"]
|
23
|
+
|
24
|
+
if s.respond_to? :specification_version then
|
25
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
26
|
+
s.specification_version = 2
|
27
|
+
|
28
|
+
if current_version >= 3 then
|
29
|
+
s.add_development_dependency(%q<echoe>, [">= 0"])
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<echoe>, [">= 0"])
|
32
|
+
end
|
33
|
+
else
|
34
|
+
s.add_dependency(%q<echoe>, [">= 0"])
|
35
|
+
end
|
36
|
+
end
|
data/ext/build_ruby.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
|
2
|
+
# Extension abuse in order to build our patched binary as part of the gem install process.
|
3
|
+
|
4
|
+
if RUBY_PLATFORM =~ /win32|windows/
|
5
|
+
raise "Windows is not supported."
|
6
|
+
end
|
7
|
+
|
8
|
+
unless RUBY_VERSION == '1.8.6'
|
9
|
+
raise "Wrong Ruby version, you're at '#{RUBY_VERSION}', need 1.8.6"
|
10
|
+
end
|
11
|
+
|
12
|
+
source_dir = File.expand_path(File.dirname(__FILE__)) + "/../ruby"
|
13
|
+
tmp = "/tmp/"
|
14
|
+
|
15
|
+
require 'fileutils'
|
16
|
+
require 'rbconfig'
|
17
|
+
|
18
|
+
def which(basename)
|
19
|
+
# system('which') is not compatible across Linux and BSD
|
20
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).detect do |directory|
|
21
|
+
path = File.join(directory, basename.to_s)
|
22
|
+
path if File.exist? path
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if which('ruby-bleak-house') and
|
27
|
+
`ruby-bleak-house -e "puts RUBY_PATCHLEVEL"`.to_i >= 902
|
28
|
+
# OK
|
29
|
+
else
|
30
|
+
# Build
|
31
|
+
Dir.chdir(tmp) do
|
32
|
+
build_dir = "bleak_house"
|
33
|
+
binary_dir = File.dirname(`which ruby`)
|
34
|
+
|
35
|
+
FileUtils.rm_rf(build_dir) rescue nil
|
36
|
+
if File.exist? build_dir
|
37
|
+
raise "Could not delete previous build dir #{Dir.pwd}/#{build_dir}"
|
38
|
+
end
|
39
|
+
|
40
|
+
Dir.mkdir(build_dir)
|
41
|
+
|
42
|
+
begin
|
43
|
+
Dir.chdir(build_dir) do
|
44
|
+
|
45
|
+
# Copy Ruby source
|
46
|
+
bz2 = "ruby-1.8.6-p230.tar.bz2"
|
47
|
+
FileUtils.copy "#{source_dir}/#{bz2}", bz2
|
48
|
+
|
49
|
+
# Extract
|
50
|
+
system("tar xjf #{bz2} > tar.log 2>&1")
|
51
|
+
File.delete bz2
|
52
|
+
|
53
|
+
Dir.chdir("ruby-1.8.6-p230") do
|
54
|
+
|
55
|
+
# Patch, configure, and build
|
56
|
+
["valgrind", "configure", "gc"].each do |patch|
|
57
|
+
system("patch -p0 < \'#{source_dir}/#{patch}.patch\' > ../#{patch}_patch.log 2>&1")
|
58
|
+
end
|
59
|
+
|
60
|
+
system("./configure --prefix=#{binary_dir[0..-5]} > ../configure.log 2>&1") # --with-static-linked-ext
|
61
|
+
|
62
|
+
# Patch the makefile for arch/sitedir
|
63
|
+
makefile = File.read('Makefile')
|
64
|
+
%w{arch sitearch sitedir}.each do | key |
|
65
|
+
makefile.gsub!(/#{key} = .*/, "#{key} = #{Config::CONFIG[key]}")
|
66
|
+
end
|
67
|
+
File.open('Makefile', 'w'){|f| f.puts(makefile)}
|
68
|
+
|
69
|
+
# Patch the config.h for constants
|
70
|
+
constants = {
|
71
|
+
'RUBY_LIB' => 'rubylibdir', #define RUBY_LIB "/usr/lib/ruby/1.8"
|
72
|
+
'RUBY_SITE_LIB' => 'sitedir', #define RUBY_SITE_LIB "/usr/lib/ruby/site_ruby"
|
73
|
+
'RUBY_SITE_LIB2' => 'sitelibdir', #define RUBY_SITE_LIB2 "/usr/lib/ruby/site_ruby/1.8"
|
74
|
+
'RUBY_PLATFORM' => 'arch', #define RUBY_PLATFORM "i686-linux"
|
75
|
+
'RUBY_ARCHLIB' => 'topdir', #define RUBY_ARCHLIB "/usr/lib/ruby/1.8/i686-linux"
|
76
|
+
'RUBY_SITE_ARCHLIB' => 'sitearchdir' #define RUBY_SITE_ARCHLIB "/usr/lib/ruby/site_ruby/1.8/i686-linux"
|
77
|
+
}
|
78
|
+
config_h = File.read('config.h')
|
79
|
+
constants.each do | const, key |
|
80
|
+
config_h.gsub!(/#define #{const} .*/, "#define #{const} \"#{Config::CONFIG[key]}\"")
|
81
|
+
end
|
82
|
+
File.open('config.h', 'w'){|f| f.puts(config_h)}
|
83
|
+
|
84
|
+
system("make > ../make.log 2>&1")
|
85
|
+
|
86
|
+
binary = "#{binary_dir}/ruby-bleak-house"
|
87
|
+
|
88
|
+
# Install binary
|
89
|
+
if File.exist? "ruby"
|
90
|
+
# Avoid "Text file busy" error
|
91
|
+
File.delete binary if File.exist? binary
|
92
|
+
exec("cp ./ruby #{binary}; chmod 755 #{binary}")
|
93
|
+
else
|
94
|
+
raise "Binary did not build"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
rescue Object => e
|
100
|
+
raise "Please see the last modified log file in #{tmp}#{build_dir}, perhaps\nit will contain a clue.\n#{e.to_s}"
|
101
|
+
end
|
102
|
+
|
103
|
+
# Success
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
data/ext/extconf.rb
ADDED