Skip to content

Instantly share code, notes, and snippets.

@erotte
Created August 2, 2010 10:00
Show Gist options
  • Save erotte/504418 to your computer and use it in GitHub Desktop.
Save erotte/504418 to your computer and use it in GitHub Desktop.
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