2015-03-30 07:14:42 +08:00
|
|
|
require_dependency 'memory_diagnostics'
|
|
|
|
|
2014-02-14 12:43:08 +08:00
|
|
|
class Admin::DiagnosticsController < Admin::AdminController
|
|
|
|
layout false
|
2017-08-31 12:06:56 +08:00
|
|
|
skip_before_action :check_xhr
|
2014-02-14 12:43:08 +08:00
|
|
|
|
|
|
|
def memory_stats
|
2015-02-10 12:54:16 +08:00
|
|
|
text = nil
|
|
|
|
|
|
|
|
if params.key?(:diff)
|
2015-03-30 07:14:42 +08:00
|
|
|
if !MemoryDiagnostics.snapshot_exists?
|
2015-02-10 12:54:16 +08:00
|
|
|
text = "No initial snapshot exists"
|
|
|
|
else
|
2015-03-30 07:14:42 +08:00
|
|
|
text = MemoryDiagnostics.compare
|
2015-02-10 12:54:16 +08:00
|
|
|
end
|
|
|
|
elsif params.key?(:snapshot)
|
2015-03-30 07:14:42 +08:00
|
|
|
MemoryDiagnostics.snapshot_current_process
|
|
|
|
text = "Writing snapshot to: #{MemoryDiagnostics.snapshot_filename}\n\nTo get a diff use ?diff=1"
|
2015-02-10 12:54:16 +08:00
|
|
|
else
|
2015-03-30 07:14:42 +08:00
|
|
|
text = MemoryDiagnostics.memory_report(class_report: params.key?(:full))
|
2015-02-10 12:54:16 +08:00
|
|
|
end
|
|
|
|
|
2017-04-10 20:01:25 +08:00
|
|
|
render plain: text
|
2014-02-14 12:43:08 +08:00
|
|
|
end
|
2014-12-08 06:54:35 +08:00
|
|
|
|
|
|
|
def dump_heap
|
|
|
|
begin
|
|
|
|
# ruby 2.1
|
|
|
|
GC.start(full_mark: true)
|
|
|
|
require 'objspace'
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
io = File.open("discourse-heap-#{SecureRandom.hex(3)}.json", 'w')
|
|
|
|
ObjectSpace.dump_all(output: io)
|
2014-12-08 06:54:35 +08:00
|
|
|
io.close
|
|
|
|
|
2017-04-10 20:01:25 +08:00
|
|
|
render plain: "HEAP DUMP:\n#{io.path}"
|
2014-12-08 06:54:35 +08:00
|
|
|
rescue
|
2017-04-10 20:01:25 +08:00
|
|
|
render plain: "HEAP DUMP:\nnot supported"
|
2014-12-08 06:54:35 +08:00
|
|
|
end
|
|
|
|
end
|
2015-02-10 08:47:44 +08:00
|
|
|
|
2014-02-14 12:43:08 +08:00
|
|
|
end
|