From b75620973f5bc431be92b07984d38cea16611a0f Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 14 Feb 2014 15:43:08 +1100 Subject: [PATCH] FEATURE: memory stats route for diagnostics in admin --- app/controllers/admin/diagnostics_controller.rb | 14 ++++++++++++++ config/routes.rb | 2 ++ script/bench.rb | 10 ++++++++++ 3 files changed, 26 insertions(+) create mode 100644 app/controllers/admin/diagnostics_controller.rb diff --git a/app/controllers/admin/diagnostics_controller.rb b/app/controllers/admin/diagnostics_controller.rb new file mode 100644 index 000000000..0a452ee00 --- /dev/null +++ b/app/controllers/admin/diagnostics_controller.rb @@ -0,0 +1,14 @@ +class Admin::DiagnosticsController < Admin::AdminController + layout false + skip_before_filter :check_xhr + + def memory_stats + + 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 +end diff --git a/config/routes.rb b/config/routes.rb index 288ecfbb9..846cf1eb2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -119,6 +119,8 @@ Discourse::Application.routes.draw do put "readonly" => "backups#readonly" end end + + get "memory_stats"=> "diagnostics#memory_stats", constraints: AdminConstraint.new end # admin namespace diff --git a/script/bench.rb b/script/bench.rb index 852290725..e153bac6b 100644 --- a/script/bench.rb +++ b/script/bench.rb @@ -7,6 +7,8 @@ require "optparse" @result_file = nil @iterations = 500 @best_of = 1 +@mem_stats = false + opts = OptionParser.new do |o| o.banner = "Usage: ruby bench.rb [options]" @@ -22,6 +24,9 @@ opts = OptionParser.new do |o| o.on("-b", "--best_of [NUM]", "Number of times to run the bench taking best as result") do |i| @best_of = i.to_i end + o.on("-m", "--memory_stats") do + @mem_stats = true + end end opts.parse! @@ -212,6 +217,11 @@ begin puts results.to_yaml + if @mem_stats + puts + puts open("http://127.0.0.1:#{@port}/admin/memory_stats#{append}").read + end + if @result_file File.open(@result_file,"wb") do |f| f.write(results)