bleak_house 3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+
2
+ BleakHouse Changelog
3
+
4
+ 3. gem version
5
+ 2. dumped Rublique once I understood what it did; replaced with a lightweight non-delta marshalling version
6
+ 1. first version
7
+
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
+
@@ -0,0 +1,18 @@
1
+ ./CHANGELOG
2
+ ./LICENSE
3
+ ./Manifest
4
+ ./README
5
+ ./Rakefile
6
+ ./init.rb
7
+ ./install.rb
8
+ ./lib/bleak_house
9
+ ./lib/bleak_house/action_controller.rb
10
+ ./lib/bleak_house/analyze.rb
11
+ ./lib/bleak_house/bleak_house.rb
12
+ ./lib/bleak_house/dispatcher.rb
13
+ ./lib/bleak_house/gruff_hacks.rb
14
+ ./lib/bleak_house/mem_logger.rb
15
+ ./lib/bleak_house/rake_task_redefine_task.rb
16
+ ./lib/bleak_house/support_methods.rb
17
+ ./lib/bleak_house.rb
18
+ ./tasks/bleak_house_tasks.rake
data/README ADDED
@@ -0,0 +1,20 @@
1
+ -----------------------------------------------------------------
2
+
3
+ BleakHouse
4
+ You need the 'gruff' gem, and 'rmagick', and all that.
5
+
6
+ To run:
7
+ RAILS_ENV=production BLEAK_HOUSE=true INTERVAL=5 ./script/server
8
+ Browse around in your app. Cause requests. Do stuff. Then:
9
+ RAILS_ENV=production rake bleak_house:analyze
10
+ And then look in log/bleak_house/.
11
+
12
+ Copyright (c) 2007 Cloudburst, LLC. See included LICENSE file. Portions
13
+ copyright Tony Arcieri and Scott Barron and used under license.
14
+
15
+ I was such a shy little thing that I seldom dared to open my lips, and never
16
+ dared to open my heart, to anybody else.
17
+ - Dickens, Bleak House
18
+
19
+ -----------------------------------------------------------------
20
+
@@ -0,0 +1,66 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'lib/bleak_house/rake_task_redefine_task'
4
+
5
+ NAME = "bleak_house"
6
+
7
+ begin
8
+ require 'rake/clean'
9
+ gem 'echoe', '>= 1.1'
10
+ require 'echoe'
11
+ require 'fileutils'
12
+
13
+ AUTHOR = "Evan Weaver"
14
+ EMAIL = "evan at cloudbur dot st"
15
+ DESCRIPTION = "BleakHouse is a Rails plugin for finding memory leaks. It tracks ObjectSpace for your entire app, and produces charts of references by controller, by action, and by object class."
16
+ CHANGES = `cat CHANGELOG`[/^([\d\.]+\. .*)/, 1]
17
+ RUBYFORGE_NAME = "fauna"
18
+ GEM_NAME = "bleak_house"
19
+ HOMEPATH = "http://blog.evanweaver.com"
20
+ RELEASE_TYPES = ["gem"]
21
+ REV = nil
22
+ VERS = `cat CHANGELOG`[/^([\d\.]+)\. /, 1]
23
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
24
+ RDOC_OPTS = ['--quiet', '--title', "bleak_house documentation", "--opname", "index.html", "--line-numbers", "--main", "README", "--inline-source"]
25
+
26
+ include FileUtils
27
+
28
+ taskmsg = File.open(File.dirname(__FILE__) + "/tasks/bleak_house_tasks.rake").readlines
29
+ taskmsg = taskmsg[0..3] + [taskmsg[7][2..-1]] + taskmsg[9..-1]
30
+
31
+ echoe = Echoe.new(GEM_NAME, VERS) do |p|
32
+ p.author = AUTHOR
33
+ p.rubyforge_name = RUBYFORGE_NAME
34
+ p.name = NAME
35
+ p.description = DESCRIPTION
36
+ p.changes = CHANGES
37
+ p.email = EMAIL
38
+ p.summary = DESCRIPTION
39
+ p.url = HOMEPATH
40
+ p.need_tar = false
41
+ p.need_tar_gz = true
42
+ p.test_globs = ["*_test.rb"]
43
+ p.clean_globs = CLEAN
44
+ p.spec_extras = {:post_install_message =>
45
+ "
46
+ Thanks for installing Bleak House #{VERS}.
47
+
48
+ For each Rails app you want to profile, you will need to add the following
49
+ rake task in RAILS_ROOT/lib/tasks/bleak_house_tasks.rake to be able to run
50
+ the analyzer:
51
+ " + taskmsg.join(" ") + "\n"}
52
+ end
53
+
54
+ rescue LoadError => boom
55
+ puts "You are missing a dependency required for meta-operations on this gem."
56
+ puts "#{boom.to_s.capitalize}."
57
+
58
+ desc 'Run the default tasks'
59
+ task :default => :test
60
+ end
61
+
62
+ desc 'Do nothing.'
63
+ Rake::Task.redefine_task("test") do
64
+ puts "There are no tests. You could totally write some, though."
65
+ # system "ruby -Ibin:lib:test test/unit/polymorph_test.rb #{ENV['METHOD'] ? "--name=#{ENV['METHOD']}" : ""}"
66
+ end
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+
2
+ require 'bleak_house'
@@ -0,0 +1 @@
1
+ puts File.open("#{File.dirname(__FILE__)}/README").read
@@ -0,0 +1,13 @@
1
+
2
+ if ENV['BLEAK_HOUSE']
3
+
4
+ require 'dispatcher' # rails
5
+
6
+ require 'bleak_house/bleak_house'
7
+ require 'bleak_house/mem_logger'
8
+ require 'bleak_house/dispatcher'
9
+ require 'bleak_house/action_controller'
10
+
11
+ BleakHouse.warn "enabled (log/#{RAILS_ENV}_bleak_house.log) (#{BleakHouse.log_interval} requests per frame)"
12
+
13
+ end
@@ -0,0 +1,16 @@
1
+
2
+ class ActionController::Base
3
+ class << self
4
+ def process_with_bleak_house(request, *args)
5
+ BleakHouse.set_request_name request
6
+ process_without_bleak_house(request, *args)
7
+ end
8
+ alias_method_chain :process, :bleak_house
9
+
10
+ def process_with_exception_with_bleak_house(request, *args)
11
+ BleakHouse.set_request_name request, "/error"
12
+ process_with_exception_without_bleak_house(request, *args)
13
+ end
14
+ alias_method_chain :process_with_exception, :bleak_house
15
+ end
16
+ end
@@ -0,0 +1,139 @@
1
+
2
+ require 'rubygems'
3
+ require 'fileutils'
4
+ require 'base64'
5
+
6
+ gem 'gruff', '= 0.2.8'
7
+ require 'gruff'
8
+
9
+ # require, but make rdoc not whine
10
+ load "#{File.dirname(__FILE__)}/gruff_hacks.rb"
11
+ load "#{File.dirname(__FILE__)}/support_methods.rb"
12
+
13
+ Gruff::Base::LEFT_MARGIN = 200
14
+ Gruff::Base::NEGATIVE_TOP_MARGIN = 30
15
+ Gruff::Base::MAX_LEGENDS = 28
16
+
17
+ class BleakHouse
18
+ class Analyze
19
+
20
+ DIR = "#{RAILS_ROOT}/log/bleak_house/"
21
+
22
+ def initialize(data, increments, name)
23
+ @data = data
24
+ @increments = increments
25
+ @name = name
26
+ end
27
+
28
+ def draw
29
+ g = Gruff::Line.new("1024x768")
30
+ g.title = @name
31
+ g.x_axis_label = "time"
32
+ g.legend_font_size = g.legend_box_size = 14
33
+ g.title_font_size = 24
34
+ g.marker_font_size = 14
35
+
36
+ @data.map do |key, values|
37
+ name = if key.to_s == ""
38
+ '[Unknown]'
39
+ else
40
+ # elsif key =~ Regexp.new(@specials.keys.join('|'))
41
+ # name = "#{key} (#{values.to_i.max / (2**10)} MB)"
42
+ # @specials.each do |regex, scale|
43
+ # values.map! {|x| x * scale} if key =~ regex
44
+ # end
45
+ # else
46
+ "#{key.gsub(/.*::/, '')} (#{values.to_i.max})"
47
+ end
48
+ [name, values]
49
+ end.sort_by do |key, values|
50
+ 0 - key[/.*?([\d]+)\)$/, 1].to_i
51
+ end.each do |key, values|
52
+ g.data(key, values.to_i)
53
+ end
54
+
55
+ labels = {}
56
+ mod = (@increments.size / 4.0).ceil
57
+ @increments.each_with_index do |increment, index|
58
+ labels[index] = increment.split(" ").last if (index % mod).zero?
59
+ end
60
+ g.labels = labels
61
+
62
+ g.minimum_value = 0
63
+ # g.maximum_value = @maximum
64
+
65
+ g.write(@name.to_filename + ".png")
66
+ end
67
+
68
+ def self.aggregate(data, selector, namer)
69
+ aggregate_data = {}
70
+ increments = []
71
+ data.each_with_index do |frameset, index|
72
+ increments << frameset.time
73
+ frameset.data.keys.select do |key|
74
+ key =~ selector #or key =~ Regexp.new(specials.keys.join('|'))
75
+ end.each do |key|
76
+ aggregate_data[key.to_s[namer, 1]] ||= []
77
+ aggregate_data[key.to_s[namer, 1]][index] += frameset.data[key].to_i
78
+ end
79
+ end
80
+ [aggregate_data, increments]
81
+ end
82
+
83
+ def self.build_all(filename)
84
+ unless File.exists? filename
85
+ puts "No data file found: #{filename}"
86
+ exit
87
+ end
88
+ FileUtils.rm_r(DIR) rescue nil
89
+ Dir.mkdir(DIR)
90
+
91
+ Dir.chdir(DIR) do
92
+
93
+ puts "Parsing data"
94
+ data = File.open(filename).readlines.map do |line|
95
+ Marshal.load Base64.decode64(line)
96
+ end
97
+
98
+ # data_maximum = data.flatten.inject(0) do |max, el|
99
+ # if el.is_a? Hash
100
+ # current_max = el.merge({:"real memory" => 0, :"virtual memory" => 0}).values.to_i.max
101
+ # current_max if max < current_max
102
+ # end or max
103
+ # end
104
+ # mem_maximum = data.flatten.inject(0) do |max, el| # only real memory (RSS) for now
105
+ # (el["real memory"] if el.is_a?(Hash) and max < el["real memory"]) or max
106
+ # end
107
+ # mem_scale = data_maximum / mem_maximum.to_f
108
+ # scales = {/memory$/ => mem_scale}
109
+
110
+ puts "By controller"
111
+ controller_data, increments = aggregate(data, //, /^(.*?)($|\/|::::)/)
112
+ Analyze.new(controller_data, increments, "objects by controller").draw
113
+
114
+ # in each controller, by action
115
+ puts "By action"
116
+ controller_data.keys.each do |controller|
117
+ puts " ...in #{controller} controller"
118
+ Dir.descend(controller) do
119
+ action_data, increments = aggregate(data, /^#{controller}($|\/|::::)/, /\/(.*?)($|\/|::::)/)
120
+ Analyze.new(action_data, increments, "objects by action in /#{controller}").draw
121
+
122
+ # in each action, by object class
123
+ action_data.keys.each do |action|
124
+ action = "unknown" if action.to_s == ""
125
+ puts " ...in #{action} action"
126
+ Dir.descend(action) do
127
+ class_data, increments = aggregate(data, /^#{controller}#{"\/#{action}" unless action == "unknown"}($|\/|::::)/,
128
+ /::::(.*)/)
129
+ Analyze.new(class_data, increments, "objects by class in /#{controller}/#{action}").draw
130
+ end
131
+ end
132
+
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ end
139
+ end
@@ -0,0 +1,33 @@
1
+
2
+ class BleakHouse
3
+ cattr_accessor :last_request_name
4
+ cattr_accessor :dispatch_count
5
+ cattr_accessor :log_interval
6
+
7
+ self.dispatch_count = 0
8
+ self.log_interval = (ENV['INTERVAL'] and ENV['INTERVAL'].to_i or 10)
9
+
10
+ def self.set_request_name request, other = nil
11
+ self.last_request_name = "#{request.parameters['controller']}/#{request.parameters['action']}/#{request.request_method}#{other}"
12
+ end
13
+
14
+ def self.debug s
15
+ s = "#{name.underscore}: #{s}"
16
+ ::ActiveRecord::Base.logger.debug s if ::ActiveRecord::Base.logger
17
+ end
18
+
19
+ def self.warn s
20
+ s = "#{name.underscore}: #{s}"
21
+ if ::ActiveRecord::Base.logger
22
+ ::ActiveRecord::Base.logger.warn s
23
+ else
24
+ $stderr.puts s
25
+ end
26
+ end
27
+
28
+ LOGFILE = "#{RAILS_ROOT}/log/bleak_house_#{RAILS_ENV}.dump"
29
+ if File.exists?(LOGFILE)
30
+ File.rename(LOGFILE, "#{LOGFILE}.old")
31
+ warn "renamed old logfile"
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+
2
+ # crazyness
3
+
4
+ class Dispatcher
5
+ class << self
6
+ def prepare_application_with_bleak_house
7
+ prepare_application_without_bleak_house
8
+ BleakHouse.dispatch_count += 1
9
+ BleakHouse::MemLogger.snapshot('core rails')
10
+ end
11
+ alias_method_chain :prepare_application, :bleak_house
12
+
13
+ def reset_after_dispatch_with_bleak_house
14
+ BleakHouse::MemLogger.snapshot(BleakHouse.last_request_name || 'unknown')
15
+ if (BleakHouse.dispatch_count % BleakHouse.log_interval).zero?
16
+ BleakHouse.warn "wrote frameset (#{BleakHouse.dispatch_count} dispatches)"
17
+ BleakHouse::MemLogger.log(BleakHouse::LOGFILE)
18
+ end
19
+ reset_after_dispatch_without_bleak_house
20
+ end
21
+ alias_method_chain :reset_after_dispatch, :bleak_house
22
+ end
23
+ end
@@ -0,0 +1,56 @@
1
+
2
+ class Gruff::Base
3
+
4
+ def draw_legend
5
+ @legend_labels = @data.collect {|item| item[DATA_LABEL_INDEX] }
6
+
7
+ legend_square_width = @legend_box_size # small square with color of this item
8
+ legend_left = 10
9
+
10
+ current_x_offset = legend_left
11
+ current_y_offset = TOP_MARGIN + TITLE_MARGIN + @title_caps_height + LEGEND_MARGIN
12
+
13
+ debug { @d.line 0.0, current_y_offset, @raw_columns, current_y_offset }
14
+
15
+ @legend_labels.each_with_index do |legend_label, index|
16
+
17
+ next if index > MAX_LEGENDS
18
+ legend_label = "Some not shown" if index == MAX_LEGENDS
19
+
20
+ # Draw label
21
+ @d.fill = @font_color
22
+ @d.font = @font if @font
23
+ @d.pointsize = scale_fontsize(@legend_font_size)
24
+ @d.stroke('transparent')
25
+ @d.font_weight = NormalWeight
26
+ @d.gravity = WestGravity
27
+ @d = @d.annotate_scaled( @base_image,
28
+ @raw_columns, 1.0,
29
+ current_x_offset + (legend_square_width * 1.7), current_y_offset,
30
+ legend_label.to_s, @scale)
31
+
32
+ if index < MAX_LEGENDS
33
+ # Now draw box with color of this dataset
34
+ @d = @d.stroke('transparent')
35
+ @d = @d.fill @data[index][DATA_COLOR_INDEX]
36
+ @d = @d.rectangle(current_x_offset,
37
+ current_y_offset - legend_square_width / 2.0,
38
+ current_x_offset + legend_square_width,
39
+ current_y_offset + legend_square_width / 2.0)
40
+ end
41
+
42
+ @d.pointsize = @legend_font_size
43
+ metrics = @d.get_type_metrics(@base_image, legend_label.to_s)
44
+ current_y_offset += metrics.height * 1.05
45
+ end
46
+ @color_index = 0
47
+ end
48
+
49
+ alias :setup_graph_measurements_without_top_margin :setup_graph_measurements
50
+ def setup_graph_measurements
51
+ setup_graph_measurements_without_top_margin
52
+ @graph_height += NEGATIVE_TOP_MARGIN
53
+ @graph_top -= NEGATIVE_TOP_MARGIN
54
+ end
55
+
56
+ end
@@ -0,0 +1,54 @@
1
+
2
+ require 'base64'
3
+
4
+ class BleakHouse::MemLogger
5
+ class << self
6
+
7
+ SEEN = {}
8
+ CURRENT = {}
9
+ TAGS = Hash.new(0)
10
+ TIMEFORMAT = '%Y-%m-%d %H:%M:%S'
11
+ VSZ = "virtual memory"
12
+ RSS = "real memory"
13
+
14
+ def log(path, with_mem = false)
15
+ File.open(path, 'a+') do |log|
16
+ log.sync = true
17
+ TAGS[VSZ], TAGS[RSS] = mem_usage if with_mem
18
+ log.puts Base64.encode64(Marshal.dump([Time.now.strftime(TIMEFORMAT), TAGS])).gsub("\n", '')
19
+ end
20
+ GC.start
21
+ end
22
+
23
+ def snapshot(tag)
24
+ # puts "bleak_house: seen: #{SEEN.size}"
25
+ CURRENT.clear
26
+ ObjectSpace.each_object do |obj|
27
+ CURRENT[obj_id = obj._bleak_house_object_id] = true
28
+ unless SEEN[obj_id]
29
+ # symbols will rapidly stabilize; don't worry
30
+ SEEN[obj_id] = "#{tag}::::#{obj._bleak_house_class}".to_sym
31
+ TAGS[SEEN[obj_id]] += 1
32
+ end
33
+ end
34
+ # puts "bleak_house: current: #{CURRENT.size}"
35
+ SEEN.keys.each do |obj_id|
36
+ TAGS[SEEN.delete(obj_id)] -= 1 unless CURRENT[obj_id]
37
+ end
38
+ # puts "bleak_house: done"
39
+ CURRENT.clear
40
+ GC.start
41
+ end
42
+
43
+ def mem_usage
44
+ `ps -x -o 'rss vsz' -p #{Process.pid}`.split(/\s+/)[-2..-1].map{|el| el.to_i}
45
+ end
46
+
47
+ end
48
+ end
49
+
50
+ class Object
51
+ alias :_bleak_house_object_id :object_id
52
+ alias :_bleak_house_class :class
53
+ end
54
+
@@ -0,0 +1,25 @@
1
+
2
+ # http://www.bigbold.com/snippets/posts/show/2032
3
+ module Rake
4
+ module TaskManager
5
+ def redefine_task(task_class, args, &block)
6
+ task_name, deps = resolve_args(args)
7
+ task_name = task_class.scope_name(@scope, task_name)
8
+ deps = [deps] unless deps.respond_to?(:to_ary)
9
+ deps = deps.collect {|d| d.to_s }
10
+ task = @tasks[task_name.to_s] = task_class.new(task_name, self)
11
+ task.application = self
12
+ task.add_comment(@last_comment)
13
+ @last_comment = nil
14
+ task.enhance(deps, &block)
15
+ task
16
+ end
17
+ end
18
+ class Task
19
+ class << self
20
+ def redefine_task(args, &block)
21
+ Rake.application.redefine_task(self, args, &block)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,47 @@
1
+
2
+ class Array
3
+ alias :time :first
4
+ alias :data :last
5
+
6
+ def sum
7
+ inject(0) {|s, x| x + s}
8
+ end
9
+
10
+ def to_i
11
+ self.map{|s| s.to_i}
12
+ end
13
+
14
+ end
15
+
16
+ class Dir
17
+ def self.descend path, &block
18
+ path = path.split("/") unless path.is_a? Array
19
+ top = path.shift
20
+ Dir.mkdir(top) unless File.exists? top
21
+ Dir.chdir(top) do
22
+ if path.any?
23
+ descend path, &block
24
+ else
25
+ block.call
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ class String
32
+ def to_filename
33
+ self.downcase.gsub(/[^\w\d\-]/, '_')
34
+ end
35
+ end
36
+
37
+ class NilClass
38
+ def +(op)
39
+ self.to_i + op
40
+ end
41
+ end
42
+
43
+ class Symbol
44
+ def =~ regex
45
+ self.to_s =~ regex
46
+ end
47
+ end
@@ -0,0 +1,13 @@
1
+
2
+ namespace :bleak_house do
3
+ desc 'Analyze and chart all data'
4
+ task :analyze do
5
+ begin
6
+ require "#{File.dirname(__FILE__)}/../lib/bleak_house/analyze"
7
+ rescue LoadError
8
+ require 'bleak_house/analyze'
9
+ end
10
+ BleakHouse::Analyze.build_all("#{RAILS_ROOT}/log/bleak_house_#{RAILS_ENV}.dump")
11
+ end
12
+ end
13
+
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: bleak_house
5
+ version: !ruby/object:Gem::Version
6
+ version: "3"
7
+ date: 2007-04-29 00:00:00 -04:00
8
+ summary: BleakHouse is a Rails plugin for finding memory leaks. It tracks ObjectSpace for your entire app, and produces charts of references by controller, by action, and by object class.
9
+ require_paths:
10
+ - lib
11
+ email: evan at cloudbur dot st
12
+ homepage: http://blog.evanweaver.com
13
+ rubyforge_project: fauna
14
+ description: BleakHouse is a Rails plugin for finding memory leaks. It tracks ObjectSpace for your entire app, and produces charts of references by controller, by action, and by object class.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message: |+
29
+
30
+ Thanks for installing Bleak House 3.
31
+
32
+ For each Rails app you want to profile, you will need to add the following
33
+ rake task in RAILS_ROOT/lib/tasks/bleak_house_tasks.rake to be able to run
34
+ the analyzer:
35
+
36
+ namespace :bleak_house do
37
+ desc 'Analyze and chart all data'
38
+ task :analyze do
39
+ require 'bleak_house/analyze'
40
+ BleakHouse::Analyze.build_all("#{RAILS_ROOT}/log/bleak_house_#{RAILS_ENV}.dump")
41
+ end
42
+ end
43
+
44
+
45
+ authors:
46
+ - Evan Weaver
47
+ files:
48
+ - ./CHANGELOG
49
+ - ./LICENSE
50
+ - ./Manifest
51
+ - ./README
52
+ - ./Rakefile
53
+ - ./init.rb
54
+ - ./install.rb
55
+ - ./lib/bleak_house
56
+ - ./lib/bleak_house/action_controller.rb
57
+ - ./lib/bleak_house/analyze.rb
58
+ - ./lib/bleak_house/bleak_house.rb
59
+ - ./lib/bleak_house/dispatcher.rb
60
+ - ./lib/bleak_house/gruff_hacks.rb
61
+ - ./lib/bleak_house/mem_logger.rb
62
+ - ./lib/bleak_house/rake_task_redefine_task.rb
63
+ - ./lib/bleak_house/support_methods.rb
64
+ - ./lib/bleak_house.rb
65
+ - ./tasks/bleak_house_tasks.rake
66
+ test_files: []
67
+
68
+ rdoc_options: []
69
+
70
+ extra_rdoc_files: []
71
+
72
+ executables: []
73
+
74
+ extensions: []
75
+
76
+ requirements: []
77
+
78
+ dependencies: []
79
+