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