Created
August 2, 2010 10:00
-
-
Save erotte/504418 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
class DebugController < ApplicationController | |
# Many Thanks to Jens Himmelreich for the Idea! | |
def heapdump | |
living_objects = Hash.new 0 | |
file_path = timestamp_filepath | |
ObjectSpace.each_object do |object| | |
living_objects[object.class] += 1 | |
end | |
sorted_array = living_objects.sort{|a,b| b[1] <=> a[1] } | |
File.open(file_path, 'w') do |file| | |
sorted_array.each do |pair| | |
file.puts "#{pair[0]} -> #{pair[1]}" | |
end | |
end | |
render :file => file_path | |
end | |
private | |
def timestamp | |
Time.now.strftime("%Y%m%d-%H:%I:%S") | |
end | |
def timestamp_filepath | |
"#{RAILS_ROOT}/log/heapdump#{timestamp}.log" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment