mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FEATURE: memory stats route for diagnostics in admin
This commit is contained in:
parent
7c8e9fc88d
commit
b75620973f
3 changed files with 26 additions and 0 deletions
14
app/controllers/admin/diagnostics_controller.rb
Normal file
14
app/controllers/admin/diagnostics_controller.rb
Normal file
|
@ -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
|
|
@ -119,6 +119,8 @@ Discourse::Application.routes.draw do
|
||||||
put "readonly" => "backups#readonly"
|
put "readonly" => "backups#readonly"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get "memory_stats"=> "diagnostics#memory_stats", constraints: AdminConstraint.new
|
||||||
|
|
||||||
end # admin namespace
|
end # admin namespace
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ require "optparse"
|
||||||
@result_file = nil
|
@result_file = nil
|
||||||
@iterations = 500
|
@iterations = 500
|
||||||
@best_of = 1
|
@best_of = 1
|
||||||
|
@mem_stats = false
|
||||||
|
|
||||||
opts = OptionParser.new do |o|
|
opts = OptionParser.new do |o|
|
||||||
o.banner = "Usage: ruby bench.rb [options]"
|
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|
|
o.on("-b", "--best_of [NUM]", "Number of times to run the bench taking best as result") do |i|
|
||||||
@best_of = i.to_i
|
@best_of = i.to_i
|
||||||
end
|
end
|
||||||
|
o.on("-m", "--memory_stats") do
|
||||||
|
@mem_stats = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
opts.parse!
|
opts.parse!
|
||||||
|
|
||||||
|
@ -212,6 +217,11 @@ begin
|
||||||
|
|
||||||
puts results.to_yaml
|
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
|
if @result_file
|
||||||
File.open(@result_file,"wb") do |f|
|
File.open(@result_file,"wb") do |f|
|
||||||
f.write(results)
|
f.write(results)
|
||||||
|
|
Loading…
Reference in a new issue