FEATURE: add process stats to memory report

This commit is contained in:
Sam 2015-02-10 12:30:53 +11:00
parent c1d93b2713
commit 1d99f5c9c0
1 changed files with 19 additions and 13 deletions

View File

@ -3,7 +3,7 @@ class Admin::DiagnosticsController < Admin::AdminController
skip_before_filter :check_xhr
def memory_stats
render text: memory_report, content_type: Mime::TEXT
render text: memory_report(class_report: params.key?(:full)), content_type: Mime::TEXT
end
def dump_heap
@ -24,7 +24,7 @@ class Admin::DiagnosticsController < Admin::AdminController
protected
def memory_report
def memory_report(opts={})
begin
# ruby 2.1
GC.start(full_mark: true)
@ -35,23 +35,25 @@ class Admin::DiagnosticsController < Admin::AdminController
classes = {}
ObjectSpace.each_object do |o|
begin
next if o == classes
if opts[:class_report]
ObjectSpace.each_object do |o|
begin
next if o == classes
classes[o.class] ||= 0
classes[o.class] += 1
rescue
# all sorts of stuff can happen here BasicObject etc.
classes[:unknown] ||= 0
classes[:unknown] += 1
classes[o.class] ||= 0
classes[o.class] += 1
rescue
# all sorts of stuff can happen here BasicObject etc.
classes[:unknown] ||= 0
classes[:unknown] += 1
end
end
classes = classes.sort{|a,b| b[1] <=> a[1]}[0..40].map{|klass, count| "#{klass}: #{count}"}
end
stats = GC.stat.map{|k,v| "#{k}: #{v}"}
counts = ObjectSpace.count_objects.sort{|a,b| b[1] <=> a[1] }.map{|k,v| "#{k}: #{v}"}
classes = classes.sort{|a,b| b[1] <=> a[1]}[0..40].map{|klass, count| "#{klass}: #{count}"}
<<TEXT
@ -63,9 +65,13 @@ GC STATS:
Objects:
#{counts.join("\n")}
Process Info:
#{`cat /proc/#{Process.pid}/status`}
Classes:
#{classes.join("\n")}
#{classes.length > 0 ? classes.join("\n") : "Class report omitted use ?full=1 to include it"}
TEXT
end
end