-
-
Save r38y/02f4378a19f9064d2da2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'set' | |
require 'json' | |
if ARGV.length != 2 | |
puts 'Usage diff_heaps [ORIG.json] [AFTER.json]' | |
exit 1 | |
end | |
origs = Set.new | |
File.open(ARGV[0], 'r').each_line do |line| | |
parsed = JSON.parse(line) | |
origs << parsed['address'] if parsed && parsed['address'] | |
end | |
diff = [] | |
File.open(ARGV[1], 'r').each_line do |line| | |
parsed = JSON.parse(line) | |
if parsed && parsed['address'] | |
diff << parsed unless origs.include? parsed['address'] | |
end | |
end | |
#diff.select{|d| | |
#d['file'] =~ /template/ && | |
#d['type'] == 'STRING' && | |
#d['value'] =~ /j____com_posts_shared__featured_html_erb/ | |
#}.each do |d| | |
#puts d['value'] | |
#end | |
diff = diff.select {|d| d['file'] =~ /template/} | |
diff.group_by do |x| | |
[x['type'], x['file'], x['line']] | |
end.map { |x,y| | |
[x, y.count] | |
}.sort { |a,b| | |
b[1] <=> a[1] | |
}.each {|x,y| | |
if y >= 5 | |
puts "Leaked #{y} #{x[0]} objects at: #{x[1]}:#{x[2]}" | |
end | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :one_request => :environment do | |
s = ActionDispatch::Integration::Session.new(Rails.application) | |
3.times { s.get('/')} | |
end | |
task :heaps => :environment do | |
s = ActionDispatch::Integration::Session.new(Rails.application) | |
s.get('/') | |
if s.response.body =~ /ActionView::Template::Error/ | |
puts 'Whoops, that resulted in an error' | |
raise | |
else | |
puts 'Sending 100 requests' | |
100.times { s.get('/') } | |
puts 'Dumping heap 1' | |
dump_stuff('1') | |
puts 'Sending 100 more requests' | |
100.times { s.get('/') } | |
puts 'Dumping heap 2' | |
dump_stuff('2') | |
end | |
end | |
def dump_stuff(id) | |
Thread.new { | |
require "objspace"; | |
ObjectSpace.trace_object_allocations_start; | |
GC.start(full_mark: true); | |
ObjectSpace.dump_all(output: File.open("heap#{id}.json", 'w')) | |
}.join | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment