Created
October 24, 2013 06:33
-
-
Save abdollar/7132292 to your computer and use it in GitHub Desktop.
ObjectSpace - record rails allocations
This file contains hidden or 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
| # Load the rails application | |
| require File.expand_path('../application', __FILE__) | |
| require 'objspace' | |
| require 'digest/md5' | |
| require 'base64' | |
| # Initialize the rails application | |
| MyApp::Application.initialize! | |
| objs = File.open("/tmp/objs.txt", 'w') | |
| at_exit { | |
| objs.close | |
| } | |
| EXISTING_IDS = {} | |
| ObjectSpace.each_object(String).to_a.each do |object| | |
| EXISTING_IDS[object.object_id / 1000] ||= [] | |
| EXISTING_IDS[object.object_id / 1000] << object.object_id | |
| end | |
| ObjectSpace.trace_object_allocations do | |
| MyApp::Application.initialize! | |
| ObjectSpace.each_object(String).to_a.each do |object| | |
| next if ObjectSpace.allocation_sourcefile(object).nil? | |
| next if ObjectSpace.allocation_sourcefile(object) == __FILE__ | |
| next if EXISTING_IDS[object.object_id / 1000] && | |
| EXISTING_IDS[object.object_id / 1000].include?(object.object_id) | |
| location = "#{ObjectSpace.allocation_sourcefile(object)}:#{ObjectSpace.allocation_sourceline(object)}" | |
| checksum = Digest::MD5.hexdigest(location) | |
| str_checksum = Digest::MD5.hexdigest(object.to_s) | |
| objs.puts "#{str_checksum} #{checksum} #{location} #{object.to_s}" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment