2014-02-14 12:43:08 +08:00
|
|
|
class Admin::DiagnosticsController < Admin::AdminController
|
|
|
|
layout false
|
|
|
|
skip_before_filter :check_xhr
|
|
|
|
|
|
|
|
def memory_stats
|
|
|
|
|
2014-02-14 13:10:26 +08:00
|
|
|
begin
|
|
|
|
# ruby 2.1
|
|
|
|
GC.start(full_mark: true)
|
|
|
|
rescue
|
|
|
|
GC.start
|
|
|
|
end
|
|
|
|
|
2014-02-14 12:43:08 +08:00
|
|
|
stats = GC.stat.map{|k,v| "#{k}: #{v}"}
|
|
|
|
counts = ObjectSpace.count_objects.map{|k,v| "#{k}: #{v}"}
|
|
|
|
|
|
|
|
render text: "GC STATS:\n#{stats.join("\n")} \n\nObjects:\n#{counts.join("\n")}",
|
|
|
|
content_type: Mime::TEXT
|
|
|
|
|
|
|
|
end
|
2014-12-08 06:54:35 +08:00
|
|
|
|
|
|
|
def dump_heap
|
|
|
|
begin
|
|
|
|
# ruby 2.1
|
|
|
|
GC.start(full_mark: true)
|
|
|
|
require 'objspace'
|
|
|
|
|
|
|
|
io = File.open("discourse-heap-#{SecureRandom.hex(3)}.json",'w')
|
|
|
|
ObjectSpace.dump_all(:output => io)
|
|
|
|
io.close
|
|
|
|
|
|
|
|
render text: "HEAP DUMP:\n#{io.path}", content_type: Mime::TEXT
|
|
|
|
rescue
|
|
|
|
render text: "HEAP DUMP:\nnot supported", content_type: Mime::TEXT
|
|
|
|
end
|
|
|
|
end
|
2014-02-14 12:43:08 +08:00
|
|
|
end
|