Add memory dump capabilities in all environments

pull/6746/head
Javier Torres 9 years ago
parent 3098e55ef9
commit ea27888642

@ -99,8 +99,9 @@ group :test do
gem 'mock_redis'
end
# Profiling
gem 'rbtrace', '0.4.8'
group :test, :development do
gem 'rbtrace', '0.4.8'
gem 'gc_tracer', '1.5.1'
gem 'memory_profiler'
end

@ -20,3 +20,20 @@ if ENV['MEMORY_REPORTING']
require 'rbtrace'
require 'memory_profiler'
end
module CartoDB
def self.memory_dump(filename)
# Dump classes (id -> name)
cls = ObjectSpace.each_object.inject(Hash.new 0) { |h, o| h[o.class.object_id] = o.class.name; h }
File.open(filename + '.classes', 'w') do |f|
JSON.dump(cls, f)
end
GC.start
# Dump objects
File.open(filename + '.dump', 'w') do |f|
ObjectSpace.dump_all(output: f)
end
end
end

Loading…
Cancel
Save