2015-03-29 19:14:42 -04:00
|
|
|
require_dependency 'memory_diagnostics'
|
|
|
|
|
2014-02-13 23:43:08 -05:00
|
|
|
class Admin::DiagnosticsController < Admin::AdminController
|
|
|
|
layout false
|
|
|
|
skip_before_filter :check_xhr
|
|
|
|
|
2015-10-18 23:02:22 -04:00
|
|
|
def dump_statement_cache
|
|
|
|
statements = Post.exec_sql("select * from pg_prepared_statements").to_a
|
|
|
|
text = ""
|
|
|
|
|
|
|
|
statements.each do |row|
|
|
|
|
text << "name: #{row["name"]} sql: #{row["statement"]}\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
text << "\n\nCOUNT #{statements.count}"
|
|
|
|
|
2017-04-10 08:01:25 -04:00
|
|
|
render plain: text
|
2015-10-18 23:02:22 -04:00
|
|
|
end
|
|
|
|
|
2014-02-13 23:43:08 -05:00
|
|
|
def memory_stats
|
2015-02-09 23:54:16 -05:00
|
|
|
text = nil
|
|
|
|
|
|
|
|
if params.key?(:diff)
|
2015-03-29 19:14:42 -04:00
|
|
|
if !MemoryDiagnostics.snapshot_exists?
|
2015-02-09 23:54:16 -05:00
|
|
|
text = "No initial snapshot exists"
|
|
|
|
else
|
2015-03-29 19:14:42 -04:00
|
|
|
text = MemoryDiagnostics.compare
|
2015-02-09 23:54:16 -05:00
|
|
|
end
|
|
|
|
elsif params.key?(:snapshot)
|
2015-03-29 19:14:42 -04:00
|
|
|
MemoryDiagnostics.snapshot_current_process
|
|
|
|
text = "Writing snapshot to: #{MemoryDiagnostics.snapshot_filename}\n\nTo get a diff use ?diff=1"
|
2015-02-09 23:54:16 -05:00
|
|
|
else
|
2015-03-29 19:14:42 -04:00
|
|
|
text = MemoryDiagnostics.memory_report(class_report: params.key?(:full))
|
2015-02-09 23:54:16 -05:00
|
|
|
end
|
|
|
|
|
2017-04-10 08:01:25 -04:00
|
|
|
render plain: text
|
2014-02-13 23:43:08 -05:00
|
|
|
end
|
2014-12-07 17:54:35 -05:00
|
|
|
|
|
|
|
def dump_heap
|
|
|
|
begin
|
|
|
|
# ruby 2.1
|
|
|
|
GC.start(full_mark: true)
|
|
|
|
require 'objspace'
|
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
io = File.open("discourse-heap-#{SecureRandom.hex(3)}.json", 'w')
|
|
|
|
ObjectSpace.dump_all(output: io)
|
2014-12-07 17:54:35 -05:00
|
|
|
io.close
|
|
|
|
|
2017-04-10 08:01:25 -04:00
|
|
|
render plain: "HEAP DUMP:\n#{io.path}"
|
2014-12-07 17:54:35 -05:00
|
|
|
rescue
|
2017-04-10 08:01:25 -04:00
|
|
|
render plain: "HEAP DUMP:\nnot supported"
|
2014-12-07 17:54:35 -05:00
|
|
|
end
|
|
|
|
end
|
2015-02-09 19:47:44 -05:00
|
|
|
|
2014-02-13 23:43:08 -05:00
|
|
|
end
|